javascript - Angular $scope not working inside modal window -


i'm following this guide implement authentication angular app , i'm having trouble accessing models inside controller.

somewhere in app, open modal window this:

loginmodal().then(function() {     // successful login, proceed page user wants     return $state.go(tostate.name, toparams); }).catch(function() {     // login failed, return home     return $state.go('home'); }); 

loginmodal() service, looks this:

myapp.service('loginmodal', function($modal, $localstorage) {     function assigncurrentuser(user) {         $localstorage.user = user;         return user;     }      return function() {         var instance = $modal.open({             templateurl: '/partials/modals/login.html',             controller: 'logincontroller',             windowclass: 'small'         });          return instance.result.then(assigncurrentuser);     }; }); 

when loginmodal() service used, opens modal window on page contains html of /partials/modals/login.html file. works perfectly. you'll notice i'm specifying controller use in modal: logincontroller.

the logincontroller written so:

myapp.controller('logincontroller', function($scope) {     $scope.login = function() {         console.log($scope.user);     }; }); 

and, finally, partial used in modal window:

<form name="loginform" novalidate method="post" ng-submit="login();">     <label>email address         <input type="email" name="email" ng-model="user.email">     </label>     <label>password         <input type="password" name="password" ng-model="user.password">     </label>     <input type="submit" value="login"> </form> 

the issue when fill out form (by populating user.email , user.password) , click submit button, undefined printed console.

basically, $scope.login function logincontroller executed, $scope.user property undefined though should populated form in modal window (with use of ng-models).

also, if put {{user.email}} modal template , populate email field, printed. know two-way data binding works.

why can't access $scope values modal window inside controller?

don't if help, had such problem routing. solution use ng-model="$parent.user.name" add $parent dependencies list in controller, , call using $scope.$parent.user.email or $scope.user.emailsometimes works. hope helped you.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -