官术网_书友最值得收藏!

Using the component in other components

We can use the about-page component in other components, as if it was a normal HTML tag. But the component is still boring, as it will always say that it shows the weather broadcast of Utrecht. We can mark the location property as an input. After that, location is an attribute that we can set from other components. It is even possible to bind it as a one-way binding. The Input decorator, which we are using here, needs to be imported just like Component:

import { Component, Input } from "angular2/core"; 
 
@Component({ 
  ... 
}) 
export class About { 
 @Input() 
 location: string = "Utrecht"; 
  collapsed = true; 
  show() { 
    this.collapsed = false; 
  } 
  hide() { 
    this.collapsed = true; 
  } 
 
  get encodedLocation() { 
    return encodeURIComponent(this.location); 
  } 
} 
主站蜘蛛池模板: 南雄市| 裕民县| 松原市| 新巴尔虎左旗| 舞阳县| 望城县| 新昌县| 思南县| 庄浪县| 广水市| 鄂尔多斯市| 秀山| 大冶市| 疏附县| 马鞍山市| 普兰县| 江北区| 汝阳县| 交城县| 新闻| 山西省| 旌德县| 古交市| 桑植县| 乐安县| 甘肃省| 云南省| 中方县| 汶川县| 磐石市| 岐山县| 东阳市| 长白| 凤阳县| 介休市| 公主岭市| 甘谷县| 池州市| 抚顺市| 焉耆| 南丹县|