簡體   English   中英

angularJs,$ rootScope。$ emit()返回數據對象

[英]angularJs, $rootScope.$emit() returns an object of data

我試圖通過$ rootScope。$ emit('name',response.data)公開服務對控制器的響應,但是它不起作用。

我的服務:

/**API Post for user login*/
        function login(username,password){
            return $http.post('/api/login/',{
                   username:username,
                   password:password
            }).then(loginSuccessFn, loginErrorFn);

            function loginSuccessFn(response, status, headers, config){
                Authentication.setAuthenticatedAccount(response.data);

                window.location = '/';
            }
            function loginErrorFn(response, status, headers,config){
                $rootScope.$emit('errorLogin', response.data);
            }

          }

我的控制器:

//Catching the Authentication.login errorFNn response.data
        $rootScope.$on('errorLogin', function(p){
            vm.isSuccess = p;
        })

這就是視圖中發生的情況:

{“ name”:“ errorLogin”,“ targetScope”:“ $ SCOPE”,“ defaultPrevented”:false,“ currentScope”:null}

有人可以幫我嗎

更改:

$rootScope.$on('errorLogin', function(p){
    vm.isSuccess = p;
});

至:

$rootScope.$on('errorLogin', function(e, p){
    vm.isSuccess = p;
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM