how to pass input parameters to an angular 2 component from index.html file

531
March 10, 2017, at 03:41 AM

I need to set input, configuration parameters, to a component that is not mentioned in index.html.

I can see how to do that for component selectors that are included in index.html.

How can I do from index.html?

Answer 1

You can have your configuration in your Main module class as below

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};  
}

LIVE DEMO

Rent Charter Buses Company
READ ALSO
Need feedback on AdWords Script

Need feedback on AdWords Script

I'm trying to implement a JavaScript code that mines through my AdWords campaigns' search queries & automatically add keywords to negative and positive keywords listAdWords has already provided me with the script

356
Livecycle Javascript Change color of Circle Object

Livecycle Javascript Change color of Circle Object

I am having difficulty accessing the circle object to change its color programmaticallyI have tried

427
Submit a form if the statement is true

Submit a form if the statement is true

I am trying to write a very simple jQuery function which will have two main propertiesThe first one will be to check if the field is empty or not

537