我无法弄清楚隔离范围是如何工作的。当我评论指令的范围部分时,我的代码似乎工作正常。谁能解释我错过的东西?
export function ExampleDirective() {
'ngInject';
let directive = {
restrict: 'E',
templateUrl: 'someurl.html',
scope: {
theFilter: '=' //isolated - if i make the scope global, it works
},
controller: ExampleController,
controllerAs: 'vm',
bindToController: true,
link: linkFunc
};
function linkFunc(scope, el, attr, vm) {
}
return directive;
}
class SymptomSearchController {
constructor ($scope) {
'ngInject';
}
}
<input type="text"
class="form-control"
ng-model="theFilter">
<example-directive theFilter="main.theFilter"></example-directive>
export class MainController { //as 'main'
constructor() {
'ngInject';
this.theFilter = "test";
}
}
答案 0 :(得分:1)
由于你在控制器内部有指令的别名,所以你应该在访问控制器的变量之前使用它。在vm.
值中添加ng-model
。
<input type="text"
class="form-control"
ng-model="vm.theFilter">