search

Home  >  Q&A  >  body text

angular.js - Value passing problem during angularjs control

There is a login button in navbarControl. Click login to open a login box with $uibModel. The controller is loginCtrl. How to pass the value from this loginCtrl to navbarControl?

.factory('data',function(){
    var myData = {loginInfo:true};
    return {
      myMenu : function(){
        return myData;
      }
    }
  })

navabarControl中 
$scope.unlogin = data.myMenu.loginInfo;

loginCtrl中
$scope.login = function(){
    //登录操作
    data.myMenu.loginInfo = true;
}

The current question is, how to detect the change in the value of data.myMenu.loginInfo in navbarControll. I changed the value of data.myMenu.loginInfo when logging in, but the value of navabarControll is still the original assignment

曾经蜡笔没有小新曾经蜡笔没有小新2795 days ago493

reply all(1)I'll reply

  • 巴扎黑

    巴扎黑2017-05-15 17:12:44

    You can add a service,service是全局单例。两个controller通过serviceshared data

    reply
    0
  • Cancelreply