我是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