[英]How to pass a value from index.html page to component.ts file in angular 4
[英]how to pass input parameters to an angular 2 component from index.html file
我需要將輸入,配置參數設置為index.html中未提及的組件。
我可以看到如何對index.html中包含的組件選擇器執行此操作。
如何從index.html進行操作?
您可以在Main模塊類中進行如下配置
import {Component, NgModule} from '@angular/core'
import {BrowserModule} from '@angular/platform-browser'
@Component({
selector: 'my-app',
template: `
<div>
<h2>{{name}} Sample</h2>
{{myConfiguration | json}}
</div>
`,
})
export class App {
name:string;
myConfiguration:any=myConfiguration;
constructor() {
console.log(myConfiguration);
this.name = 'Global Configuration'
}
}
@NgModule({
imports: [ BrowserModule ],
declarations: [ App ],
bootstrap: [ App]
})
export class AppModule {
var myConfiguration={id:1,devmode:true};
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.