是否可以將組件模板中的純字符串傳遞給另一個組件?例如..將字符串傳遞給另一個組件中的組件tpl in angular2
組分1 TPL:
<survey-step-complete-msg [messageType]="'completed-survey'"></survey-step-complete-msg>
元器件2周的.ts
import {Component, Input} from '@angular/core';
@Component({
selector: 'survey-step-complete-msg',
templateUrl: '../../../../public/template/topic/survey-step-complete-msg.html'
})
export class SurveyStepCompleteMsgComponent {
@Input() messageType;
constructor(){
console.log(this.messageType);
}
}
組分2 TPL:
<div [ngSwitch]="messageType">
<p *ngSwitchCase="completed-survey">Thanks</p>
<p *ngSwitchCase="survey-step-required-fields-missing">Stuff missing</p>
<p *ngSwitchCase="survey-required-fields-missing">Stuff missing</p>
<p *ngSwitchCase="survey-thanks-now-save">Thanks, don't forget to save.</p>
</div>
當前結果是在組件TS中@輸入始終未定義。
ahh right ok!感謝捆綁!這麼多新的sytax ..仍然試圖塞滿這一切:D – John
其實...原來,這只是在交換機中的字符串的雙重封閉丟失 – John
很高興你得到它解決。 –