我无法从HTTP请求的角度范围访问我的用户信息。我可以在开发人员工具中看到我需要的信息,但我无法访问它。如何从AngularJS访问数据范围
这是我有:
var scope = angular.element("#comment").scope();
console.log(scope);
//console.log(scope.navvm.currentUser.name);
我试着注释掉部分,但它不工作。当我运行没有评论的部分;我可以在我的开发者工具
我划掉的用户名和电子邮件看到这一点。
这里的导航控制器:
(function() {
angular
.module('meanApp')
.controller('navigationCtrl', navigationCtrl);
navigationCtrl.$inject = ['$location','authentication'];
function navigationCtrl($location, authentication) {
var vm = this;
vm.isLoggedIn = authentication.isLoggedIn();
vm.currentUser = authentication.currentUser();
}
})();
这里的导航指令:
(函数(){
angular
.module('meanApp')
.directive('navigation', navigation);
function navigation() {
return {
restrict: 'EA',
templateUrl: '/common/directives/navigation/navigation.template.html',
controller: 'navigationCtrl as navvm',
scope: '@?'
};
}
})();
你能否提供更多的上下文?通常,如果您需要访问服务中的范围变量,例如,您可以将它们作为参数传递给服务方法。您不应该以您在此尝试的方式访问范围。 – Lex
同意。它应该在服务中。这是目前的概念证明。长期来看,它将在服务中。 –
你能展示更多的周边代码吗?或者甚至是[MCVE]。 – Lex