[英]Update Firebase ref for KnockoutFire observable after bindings have been applied
[英]Is there an Angular $scope event emitted after bindings have been applied to a controller?
我在使用bindToController
选项的Angular(1.4)应用程序中使用bindToController
。 这是我的指令定义(用TypeScript编写):
export class MyDirective implements ng.IDirective {
public restrict = 'E';
public templateUrl = 'path/to/my/template.html';
public controller = 'MyController';
public controllerAs = 'vm';
public bindToController = true;
public scope = {
myScopeProperty: '@'
};
}
这按预期方式工作myScopeProperty
属性已正确绑定到控制器。 但是,此绑定过程是在构造对象之后发生的,这意味着在构造对象时,我无法执行任何依赖于此绑定属性值的逻辑。 例如(再次,在TypeScript中):
export class MyController {
public myScopeProperty;
constructor() {
// this logs "undefined", even if the my-scope-property
// attribute on the directive has a value
console.log('myScopeProperty: ' + this.myScopeProperty);
}
}
在Angular将其初始绑定值应用到该对象后,是否有一个$scope
事件可以监听到该控制器对象内?
没有此类事件,也不应有此类事件,因为单向@
绑定意味着myScopeProperty
值可能会多次更新。
$scope.$watch('vm.myScopeProperty', () => { ... }));
是观察绑定更改的推荐方法。
$timeout(() => { ... });
或$onInit
控制器挂钩 (可在1.4。中用angular-component $onInit
)可用于将代码推迟到已经插值myScopeProperty
的时间(第一次)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.