我有一个简单的指令:
let directive = {
restrict: 'EA',
templateUrl: 'app/components/video-player/video-player.html',
scope: {
someFunction:'='
},
...
}
template:
<div class="video" ng-click="vm.someFunction(vm.someId)"></div>
directive:
<video-player some-function="main.ctaClick"></video-player> //controllerAs main
export class MainController {
...
someFunction(){
// How do I get the correct this here without using $parent?
let context = this.scope.$parent.main;
}
}基本上,当双向绑定这样的函数时,我想知道是否有一种使用父作用域上下文的方法?这样做对吗?
发布于 2016-07-14 15:12:36
孤立指令是从它的父指令中分离出来的,因此名。如果父程序应该向指令提供某些内容,则应该将其作为属性传递。
可以用继承的作用域 binding instead替换孤立的作用域。但是,这可能表明存在设计缺陷。
这样做对吗?
不是的。
https://stackoverflow.com/questions/38376486
复制相似问题