加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

在AngularJs 1.7.2中使用NgRef降级Angular 5组件

发布时间:2020-12-17 07:09:55 所属栏目:安全 来源:网络整理
导读:我正在开发Angular 1.7.2中的一个项目,它利用了Angular 5/6中构建的一些组件.我们正在使用 downgradeComponent工具降级组件,一切正常. 我们最近添加了一个我们需要集成的新组件,但我们也需要访问组件属性.我正在研究ngRef指令,但这似乎不起作用,我无法在Angu
我正在开发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时,我得到了未定义(或者如果我初始化则为空对象)它在我的范围之前)

解决方法

我最终与组件所有者合作,现在将数据作为事件传回.然后我监听该事件并相应地使用这些属性

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读