import {Component, EventEmitter, Input, OnChanges,OnInit} from '@angular/core';
import {Observable} from 'rxjs/Rx';
import {Router} from '@angular/router';
import { LoginService } from '../../login/services/login.service';
import {User,SharedService} from '../../SharedService'
@Component({
selector: 'dashboard',
template: `
<div class="container">
<div class="row">
<div class="col-md-10 col-md-offset-1">
<div class="panel panel-default">
<div class="panel-heading">Dashboard</div>
<div class="panel-body">
You are logged in! <span>{{ this.user.email }} </span>
</div>
</div>
</div>
</div>
</div>
`
})
export class LogsComponent {
user:User;
constructor(ss:SharedService){
this.user=ss.getUserDetail();
}
}
由於使用laravel及其{{}}
模板等角度我需要創建在角模板和傳遞數據IM。我想要的是在我的模板中顯示來自this.user.email的模板數據。任何建議我該怎麼做?現在它的空白..但是當我顯示在console log this.user
我得到了用戶的對象。如何在角度2中傳遞模板中的數據?
當我我console.log(this.user)
得到這樣的:
object isLoggedIn: trueuser: Object created_at: "2017-03-14 09:04:42"email: "[email protected]"id: 4name: "user"updated_at: "2017-03-14 09:04:42"__proto__: Object__proto__: Object
但是,當我這樣做:console.log(this.user.email)
我得到不確定的。
這是我sharedService:
import {Component, Injectable } from '@angular/core';
export class User{
email:string;
name:string;
}
@Injectable()
export class SharedService{
user:User;
setUserDetail(res){
this.user=res;
}
getUserDetail(){
return this.user;
}
}
將'{{this.user.email}}'更改爲'{{user.email}}',您無需告訴模板您是引用「this」,因爲它是自動注入的。 – briosheje
我試過,但它的空白..我沒有得到anyhting – uzhas
介意告訴什麼** ss.getUserDetail()**返回? (對象鍵) – briosheje