繁体   English   中英

如何将输入参数从index.html文件传递到angular 2组件

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM