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

为Angular根组件/模块指定@Input()参数

发布时间:2020-12-17 07:18:21 所属栏目:安全 来源:网络整理
导读:我有3个根组件,由根AppModule引导. 你如何为其中一个组件指定@Input()参数? 也不 app-modal [id]="'hard-coded value'"/app-modalapp-modal [id]="constantExportedByAppmodule"/app-modal 由AppModalComponent获取: @Input() id: string; 它是未定义的.
我有3个根组件,由根AppModule引导.

你如何为其中一个组件指定@Input()参数?

也不

<app-modal [id]="'hard-coded value'"></app-modal>
<app-modal [id]="constantExportedByAppmodule"></app-modal>

由AppModalComponent获取:

@Input() id: string;

它是未定义的.

据我所知,你不能将@Input()传递给bootstraped组件.

但您可以使用其他方法来做到这一点 – 将值作为属性传递.

index.html:

<my-app myAttribute="myAttributeValue">
    <div>Loading...</div>
</my-app>

app.component.ts:

@Component({
    selector: 'my-app',templateUrl: 'app.component.html',styleUrls: ['app.component.css']
})
export class AppComponent {
    constructor(private elementRef:ElementRef) {
        let myAttribute = this.elementRef.nativeElement.getAttribute('myAttribute');
    }
}

(编辑:李大同)

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

    推荐文章
      热点阅读