我是AngularJs中的新成員,無法解決這個問題。變量不傳遞到控制器的視圖
我嘗試在unassuming方式的範圍內更改變量。
.controller('AuthController', function($scope,Auth) {
$scope.submit = function() {
Auth.login($scope.username,$scope.password, function(result){
$scope.result = result
});
}
})
如果驗證是使GET請求,服務器並獲取響應這樣的服務:
{ 'status': 1, 'message': "User does not found!"}
但我的變量不會在我的模板刷新。當我把這個
$scope.result = { 'status': 1, 'message': "User does not found!"}
以外的函數$ scope.submit。它工作正常。
這是我的路由。
$stateProvider
.state('index', {
url: "/",
templateUrl: "/static/templates/_index.html",
})
我的模板是。
<div class="alert" >{{ result.message }}</div>
有人可以解釋我,我做錯了什麼? 謝謝。
這是我的服務。
function login(username, password, callback) {
return $http.post('/api/login/', {
username: username, password: password
}).success(callback);
}
插入
Auth.login($scope.username,$scope.password, function(result){
$scope.result = result
console.log($scope.result);
後,我看到我的螢火正確的數據。 。
對象{狀態= 1,消息= 「!用戶沒有找到」}
$範圍$適用(); - 給我錯誤:[$ rootScope:inprog] http://errors.angularjs.org/1.4.0/ $ rootScope/inprog?p0 =%24digest
嘗試'$範圍$適用();'$ scope.result =結果後';' –
什麼'的console.log(結果)在'你在'$ scope.result = result'之前的回調說? – Fissio
你是否在調用提交函數somwhere? – nikhil