我有一个名为如下的 Controller :
<div ng-controller="MainController as main" class="containerWrap">
我尝试这样做来选择我的 Controller 以进一步发挥作用:-
var a = document.querySelector('[ng-controller=MainController as main]');
var b = angular.element(chatElement).scope();
它给出了一个错误:-
Uncaught SyntaxError: Failed to execute 'querySelector' on 'Document': '[ng-controller=MainController as main]' is not a valid selector.
我也尝试了 MainController :-
这给出了:-
a=null
b=undefined
有人可以帮忙吗?
最佳答案
var a = document.querySelector('[ng-controller="MainController as main"]');
关于javascript - Angularjs 中 Controller 的文档查询选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28473616/