繁体   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