2014-12-12 4 views
0

라우터에서 Iron-router로 Meteor 프로젝트를 업데이트했습니다. Iron-router를 사용하여 클라이언트/서버 측 라우팅을 만들었습니다.Meteor 템플릿에서 각도 조절기를 호출 할 수 없습니다.

철분 라우터로 업데이트 한 후 Submit 버튼을 눌렀을 때 LoginController를 호출하는 데 문제가 있습니다. 제출 버튼을 클릭해도 doLogin 기능으로 이동하지 않습니다. angular.doLogin 함수의 모든 기능을 전달할 때 로그인 기능을 처리합니다.

클라이언트 측 경로 :

Router.route('/', 'login'); 

Router.route('/login', function() { 
    this.render('login'); 
}); 

로그인 템플릿 :

<template name="login"> 
    <div class="login-box" ng-controller="LoginController">   
     <h6> 
      <span>Welcome!</span> 
      Please log in using your username and password. 
     </h6> 
     <form ng-submit="doLogin(); 
         isClick = false" name="myform" > 
      <fieldset> 
       <input type="text" id="login-username" placeholder="Username" name="username" ng-model="username" autocomplete="off" ng-click="msg = ''"> 
       <input type="password" id="login-password" placeholder="Password" name="password" ng-model="password" autocomplete="off"> 
      </fieldset> 
      <span>{{msg.message}}</span> 
     <button id="but" type="submit" ng-disabled="!username || !password">log in</button> 
     </form> 
    </div> 
</template> 

로그인 컨트롤러 : 나는이 문제를 해결할 수 있었다

angular.module('RSC').controller('LoginController', function ($scope, $route, $routeParams, $location, $http, $window, $sce) { 
    $scope.loggedIn = $window.sessionStorage['loggedIn'] ? angular.fromJson($window.sessionStorage['loggedIn']) : {status: false}; 
    $scope.sessionid = Meteor.createSessionId(); 
    // Add the login method 
    $scope.doLogin = function() { 
     var username = $scope.username; 
     var password = $scope.password; 
     // Adding the login to help generate the clientId 
     if (!$window.localStorage['clientid_' + username]) { 
      $window.localStorage['clientid_' + username] = Meteor.RSCRandomNumber(); 
     } 
     // Get client id from local storage 
     var clientid = $window.localStorage['clientid_' + username]; 
     // build the parameters 
     var dataSent = {"username": username, "password": password, "clientid": clientid}; 
     return $http({ 
      url: '/req/login', 
      method: 'POST', 
      data: jQuery.param(dataSent), 
      headers: {'Content-Type': 'application/x-www-form-urlencoded'} 
     }).error(function (err) { 
      $scope.msg = err; 

     }).success(function (result) { 
      //resolve the promise as the data 
      if (!result.hasOwnProperty('info')) { 
       $scope.username = ""; 
       $scope.password = ""; 
       $scope.msg = result.error; 
       $window.sessionStorage['userInfo'] = JSON.stringify({}); 
       $window.sessionStorage['loggedIn'] = JSON.stringify({status: false}); 
      } else { 
       $window.sessionStorage['userInfo'] = JSON.stringify(result.info); 
       $window.sessionStorage['loggedIn'] = JSON.stringify({status: true}); 
       $scope.msg = ""; 
       Session.set("vendorId", result.info.vendorId); 
       $location.path("/home"); 
      } 
     }); 
    }; 
}); 

답변

0

는 다음과 같은 솔루션이 나를 도와 : https://github.com/Urigo/angular-meteor/issues/48

if (Meteor.isClient) { 
    Router.onAfterAction(function (req, res, next) { 
     Tracker.afterFlush(function() { 
      angular.element(document).injector().invoke(['$compile', '$document', '$rootScope', 
       function ($compile, $document, $rootScope) { 
        $compile($document)($rootScope); 
        if (!$rootScope.$$phase) 
         $rootScope.$apply(); 
       } 
      ]); 
     }); 
    }); 

} 
관련 문제