ses*_*ses 7 javascript scope jasmine angularjs
我期待从我的help-button指令中获得孤立范围的东西.
it('should contain proper scope, depending on attributes', function() {
var el = compile('<help-button context-id="1"></help-button>')(scope);
scope.$digest();
console.log("el: " + el);
console.log('Isolated scope: ' + el.isolateScope());
..
});
Run Code Online (Sandbox Code Playgroud)
- 在每次测试之前
beforeEach(inject(function($compile, $rootScope, $injector) {
compile = $compile;
scope = $rootScope.$new(); ...
Run Code Online (Sandbox Code Playgroud)
它打印:
'el: [Object Object]'
'Isolated scope: undefined'
Run Code Online (Sandbox Code Playgroud)
问题是:为什么我要回来未定义?即使在隔离范围内没有任何内容,它仍然应该是空的{}对象.但无论如何 - 测试是错误的 - 它没有显示那里(实际上)包含数据的孤立范围.
我真笨.
但是会回答我自己的问题,因为"愚蠢就像愚蠢一样" - 也就是说,可能是曾经做过同样的事情(或者对于我自己的未来).
问题helpbutton.html在于我的指令正在使用(我在这个问题中没有显示/提及).
所以这templateUrl 是指helpbutton.html应该正确编译为html的文件.
一旦我查看el.html()输出,我得到它没有正确渲染(有一些丢失的标签或东西).
吴丹就是为什么我不能得到任何scope来自element.
(如果模板没有正确呈现给html,那么在日志上有一些异常会很好)
| 归档时间: |
|
| 查看次数: |
2739 次 |
| 最近记录: |