[英]Using NgRef on downgraded Angular 5 component in AngularJs 1.7.2
我正在开发Angular 1.7.2中的一个项目,它利用了Angular 5/6中构建的一些组件。 我们正在使用downgradeComponent工具降级组件,一切正常。
我们最近添加了一个我们需要集成的新组件,但我们也需要访问组件属性。 我正在研究ngRef指令,但这似乎不起作用,我无法在Angular文档之外找到任何其他ngRef示例。 当我添加ngRef并将其绑定到当前作用域中的变量时,它永远不会被分配。 任何帮助,将不胜感激!
Angular 5组件
export class ImportedComponent implements OnInit {
variable1: boolean = true;
variable2: boolean = false;
constructor(private certService: ImportedComponent) { }
ngOnInit() {
this.variable1 = true;
this.variable2 = false
}
}
Html - w / AngularJS 1.7.2
<imported ng-ref="importedProperty" ></imported>
<custom-button ng-if="importedProperty.variable1" [disabled]="!importedProperty.variable2"></custom-button>
降级
angular
.module("blah", [])
.directive(
"imported",
downgradeComponent({ component: ImportedComponent }) as angular.IDirectiveFactory
);
导入组件的降级正在运行,因为HTML正在显示,我能够看到console.log()从他们的结束发生,但是当我尝试访问importedProperty
,我得到了未定义(或者如果我初始化则为空对象)它在我的范围之前)
我最终与组件所有者合作,现在将数据作为事件传回。 然后我监听该事件并相应地使用这些属性
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.