【发布时间】:2021-12-14 18:59:30
【问题描述】:
我创建了一个私有 npm 包,我可以使用 html 中的此代码在我的其他应用程序中运行:
<app-header-name></app-header-name>
这是它运行的 npm 包中的代码:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-header-name',
templateUrl: './header.component.html',
styleUrls: ['./header.component.css'],
})
export class HeaderComponent implements OnInit {
public blob: any;
constructor() {}
ngOnInit(): void {
console.log(this.blob);
}
}
这是 npm 包中的 html 代码:
<div class="row">
<div class="col d-flex justify-content-center">
Click the button to download the template
</div>
</div>
我的问题是,如何将我的应用程序中的变量传递到 npm 包中的变量 blob 中?我尝试了以下方法,它只是控制台记录了“未定义”:
<app-header-name blob="bazinga"></app-header-name>
另外,有没有办法从 npm 包传回数据?例如,它将接收字符串 blob 变量,然后在其中添加另一个单词并将其传递回主应用程序?
【问题讨论】:
-
是 Angular 组件还是自定义元素 web 组件? -
@abhishek khandait 我认为这是一个角度组件
标签: javascript node.js angular typescript npm