5
我正在写一个指令测试,执行测试模板(这是正确加载)时,只呈现为<!-- ng-repeat="foo in bar" -->
对于初学者的相关部分代码:
测试
...
beforeEach(inject(function ($compile, $rootScope, $templateCache) {
var scope = $rootScope;
scope.prop = [ 'element0', 'element1', 'element2' ];
// Template loading, in the real code this is done with html2js, in this example
// I'm gonna load just a string (already checked the problem persists)
var template = '<strong ng-repeat="foo in bar"> <p> {{ foo }} </p> </strong>';
$templateCache.put('/path/to/template', [200, template, {}]);
el = angular.element('<directive-name bar="prop"> </directive-name>');
$compile(el)(scope);
scope.$digest(); // <--- here is the problem
isolateScope = el.isolateScope();
// Here I obtain just the ng-repeat text as a comment
console.log(el); // <--- ng-repeat="foo in bar" -->
}));
...
指令
该指令是相当简单的,它是没有问题的(外测试一切正常就好了):
app.directive('directiveName', function() {
return {
restrict : 'E',
replace : true,
scope : {
bar : '='
},
templateUrl : '/path/to/template', // Not used in this question, but still...
});
的详细原因:
- 该指令,测试外,正常工作
- 如果我将模板更改为如下简单的东西:
<h3> {{ bar[0] }} </h3>
测试工作正常 - rootScope是l oaded正确
- 的isolateScope结果
undefined