将值从cshtml传递到组件

时间:2017-02-24 02:08:38

标签: angular

我正在使用MVC结构,我有一个cstmh页面,我将spme值传递给我的home组件。我没有定义,也不确定为什么

CSHTML

<home [gwLinkID]="11111"></home>
    <ng-component></ng-component>

也尝试了

<home gwLinkID="11111"></home>
<ng-component></ng-component>

home.component

import { Component, OnInit, Input, ElementRef, CUSTOM_ELEMENTS_SCHEMA} from '@angular/core';
import { NavMenuComponent } from './navmenu/navMenu.component';


    @Input() gwLinkID: number;

    errorMessage: string;

    constructor(elm: ElementRef) {
        this.gwLinkID = elm.nativeElement.getAttribute('gwLinkID'); also tried


    }

我想念的是什么

app.component.html

<router-outlet></router-outlet>

app.component

import { Component, OnInit, Input, ElementRef } from '@angular/core';


@Component({

    moduleId: module.id,
    templateUrl: 'app.component.html'


})
export class AppComponent {



}

app.module

@NgModule({

    imports: [BrowserModule, FormsModule, ReactiveFormsModule,
        HttpModule,
        RouterModule.forRoot([
            { path: 'welcome', component: WelcomeComponent },
            { path: '', redirectTo: 'welcome', pathMatch: 'full' },
            { path: '**', redirectTo: 'welcome', pathMatch: 'full' }

        ]),


        CommonModule, NavMenuModule, TabModule, SharedModule


    ],
    declarations: [AppComponent, WelcomeComponent],
    providers: [],
    bootstrap: [AppComponent]

})
export class AppModule { }

0 个答案:

没有答案