Dyl*_*lan 8 angularjs angularjs-directive angular
我正在开发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
}
}
Run Code Online (Sandbox Code Playgroud)
Html - w/AngularJS 1.7.2
<imported ng-ref="importedProperty" ></imported>
<custom-button ng-if="importedProperty.variable1" [disabled]="!importedProperty.variable2"></custom-button>
Run Code Online (Sandbox Code Playgroud)
降级
angular
.module("blah", [])
.directive(
"imported",
downgradeComponent({ component: ImportedComponent }) as angular.IDirectiveFactory
);
Run Code Online (Sandbox Code Playgroud)
降级导入的组件正在运行,因为HTML正在显示,我能够看到console.log()从他们的结束发生,但是当我尝试访问时importedProperty,我得到未定义(或者如果我初始化它的空对象)因此在我的范围之前)