我使用$("#div1").load("aa.html")
加载" aa.html"进入一个网页,有一个" ng-repeat"指令在" aa.html"中加载后," ng-repeat"没有被angularjs执行,它直接出现在DOM中,但如果我直接放置" aa.html" $("#div1")内的内容,可以由angularjs执行。我怎样才能让angularjs执行这个" ng-repeat"在jquery加载此页面后?
答案 0 :(得分:2)
您需要注册控制器
function registerController(moduleName, controllerName, template, container) {
// Load html file with content that uses Ctrl controller
//$(template).appendTo(container);
// Here I cannot get the controller function directly so I
// need to loop through the module's _invokeQueue to get it
var queue = angular.module(moduleName)._invokeQueue;
for (var i = 0; i < queue.length; i++) {
var call = queue[i];
if (call[0] == "$controllerProvider" &&
call[1] == "register" &&
call[2][0] == controllerName) {
controllerProvider.register(controllerName, call[2][1]);
}
}
angular.injector(['ng', moduleName]).invoke(function ($compile, $rootScope) {
$compile($("#" + template))($rootScope);
$rootScope.$apply();
});
}
之后,在你的jquery成功registerController(&#39; appname&#39;,&#39; controller&#39;,&#34; temolatename&#34;)
angular.element("element").scope().run();
angular.element("element").scope().$apply();