角度分量不更新

时间:2017-12-09 22:36:56

标签: angularjs angularjs-components

我正在尝试更新angularjs组件,但组件未更新。 将控制器中的isLoggedin设置为false并在registerUser中提交用户信息后将isLoggedin更改为true,但它不会更新导航栏中的范围。

角度分量是

.component('navBar',{
controller: "registerController",
bindings:{
    nav:'<'
},
controllerAs:'vm',
templateUrl:'./components/navbar.html'
})

模板是

<header  >
<div class="menu">
    <div id="websitelogo" class="logo">
      <h1><a href="/">escapo.in</a></h1>
    </div>
    <form id="search-form" >
      <input  name='search' ng-model="search" placeholder='Search ' type="text"/>
      <input id='button-submit' type='submit' ng-click="searchNav();" value='Search'/>
    </form>
  <a href="javascript:void(0)" id="clickEvent"  onclick="openNav();" class="collapse">&#9776;</a>
  <nav class="navbar">
    <ul id="links" >
      <li  ng-if="isLoggedin">
          <div class="dropdown">
              <button class="dropbtn" onclick="openDropDown()">{{vm.username}}
              <i class="fa fa-caret-down"></i>
            </button>
            <div class="dropdown-content" id="myDropdown">
              <a href="#">Link 1</a>
              <a href="#">Link 2</a>
              <a href="#">Link 3</a>
            </div>
          </div>
      </li>
      <li  ng-if="vm.isLoggedin"><a href="/login" class="fa fa-sign-in"> Login {{vm.isLoggedin}}</a> </li>
      <li  ng-show="vm.isLoggedin"><a href="/register" class="fa fa-user"> Sign up</a> </li>
      <li><a href="/">{{vm.isLoggedin}}</a></li>
    </ul>
  </nav>
  </div>
</header>

控制器

app.controller('registerController',["$q","$scope","webApi","Handler","redirect","$state","$location",
function($q,$scope,webApi,Handler,redirect,$state,$location){
  var defered = $q.defer();

var vm = this;
  vm.isLoggedin = false;

//login function 
$scope.login = function() {
    var data = {
        email: $scope.email,
        password: $scope.password
    };
        webApi.login(data)
}

//register User
$scope.RegisterUser = function() {
    var data ={
        email : $scope.email,
        password : $scope.password,
        username: $scope.username,
        dob : $scope.day +" "+ $scope.mon + " " +$scope.year,
        gender : $scope.gen
    }
    webApi.register(data)
    .then(function(response){
      console.log(response);
      vm.isLoggedin == true;
      console.log($scope.isLoggedin);
    },function(err){
      defered.reject(err);
    });
}
}]);

这里我声明isLogged为false并且在registerUser之后我想将isLoggedin更新为true。

0 个答案:

没有答案