0
EJS變量Angular2部件
我特林傳遞模型數據對象,它是從EJS模板到angular2部件JSON對象。這裏是我的組件代碼,它有一個名爲測試的輸入。我列出了我試圖使其工作的選項。@input不是在角2組分工作
import {Component, OnInit, Input } from "@angular/core";
import { Router } from "@angular/router";
import {Location} from '@angular/common';
declare var $:JQueryStatic;
@Component({
selector: "app-loader",
templateUrl: "views/app-index.html"
})
export class AppComponent {
public viewType;
@Input() test: string;
constructor(private router: Router, private location: Location) {
// console.log(this.providers);
switch (location.path()) {
case '/login':
this.viewType = "login";
break;
default:
this.viewType = "/";
break;
}
}
ngOnInit() {
console.log(this.test);
$("app-loader").addClass("md");
}
}
薪火EJS模板數據如下:
選項1:
<app-loader [test]="'<%= JSON.stringify(providers) %>'">Loading...</app-loader>
選項2:
<app-loader [test]="providers">Loading...</app-loader>
如果'AppComponent'是根組件然後它不會工作http://stackoverflow.com/questions/39614451/angular-2-input-binding -does - 不工作/ 39614592#39614592 – yurzui