angularjs - Variable does not pass to the view from the controller -


i new in angularjs , can not figure out such problem.

i try change variable in scope unassuming way.

.controller('authcontroller',  function($scope,auth) {       $scope.submit = function() {           auth.login($scope.username,$scope.password, function(result){               $scope.result = result              });       }         }) 

where auth service makes request server , gets response this:

{ 'status': 1,  'message': "user not found!"} 

but variable not refresh in template. when put

$scope.result = { 'status': 1,  'message': "user not found!"} 

outside function $scope.submit. works fine.

this routing.

$stateprovider     .state('index', {         url: "/",         templateurl: "/static/templates/_index.html",     })  

my template is.

<div class="alert" >{{ result.message }}</div> 

can explaine me do wrong? thanks.

this service.

function login(username, password, callback) {   return $http.post('/api/login/', {     username: username, password: password   }).success(callback);  } 

after inserting

auth.login($scope.username,$scope.password, function(result){ $scope.result = result    console.log($scope.result);   

i see correct data in firebug.

object { status=1, message="user not found!"}

$scope.$apply(); - gives me error: [$rootscope:inprog] http://errors.angularjs.org/1.4.0/$rootscope/inprog?p0=%24digest

are sure auth.login() doesn't return promise. looks wants to, in case try...

auth.login($scope.username, $scope.password)     .then(function(result){         $scope.result = result        }); 

hard without seeing auth service.


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -