-1
각도가 2 인 MVC를 사용하고 있습니다. ViewBag 값 또는 하드 코딩 된 값을 app.component.ts에 대한 입력으로 전달하려고하면 null 값이 표시됩니다. 난각도 2 루트 구성 요소에 ViewBag 전달
index.cshtml
@{
ViewData["Title"] = "Home Page";
}
<div>
<pm-app [linkID][email protected]></pm-app>
</div>
app.component.ts
행운으로하여 elementRef를 사용하여 시도import { Component, OnInit,Input,ElementRef} from '@angular/core';
import { NavMenuService } from './navmenu/navMenu.service';
//import { ITitle } from './app';
@Component({
selector: 'pm-app',
moduleId: module.id,
templateUrl: 'app.component.html',
providers: [NavMenuService]
})
export class AppComponent implements OnInit {
@Input() linkID: any;
pageTitle: any[];
title: string;
titleID: number;
errorMessage: string;
constructor(private _navMenuService: NavMenuService, elm: ElementRef) {
this.linkID = elm.nativeElement.getAttribute('linkID');
console.log('linkid cons: ' + this.linkID);
}
ngOnInit(): void {
console.log('linkid: ' + this.linkID);
this._navMenuService.getLinkName(this.linkID)
.subscribe(
data => {
this.titleID = data.result.LinkID;
this.title = data.result.LinkName;
},
error => this.errorMessage = <any>error);
}
}
는 Console에 출력
linkid cons: null
linkid : null
당신은 무엇을 생각 말해 줄 수 내가 빠졌어?