I am trying to use Angular 2 with ASP.NET MVC, but cannot find a good way of mapping to a view to a component. Let's say I have a HomeController with an Index action and an Index.cshtml view. Inside the view I add an <home></home> element to be mapped to my Angular 2 component's selector.
import { Component } from '@angular/core';
@Component({
selector: 'home',
template: '<h1>Home component</h1>'
})
export class HomeComponent {
}
My component will not be triggered unless I add the component to the bootstrap property in my AppModule. This will cause my app to have several components inside the bootstrap property.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { HomeComponent } from './home.component';
@NgModule({
imports: [BrowserModule],
declarations: [AppComponent, HomeComponent],
bootstrap: [AppComponent, HomeComponent]
})
export class AppModule {
}
Is this the correct way to do it?
If I have another component's element selector inside a partial view, only my first partial view's component will be called. How do I make a component being called every time the partial view is rendered? Even if my partial view is rendered multiple times on the same page?