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

  • TypeScript Blueprints
  • Ivo Gabe de Wolff
  • 131字
  • 2021-07-14 10:59:29

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); 
  } 
} 
主站蜘蛛池模板: 聂荣县| 沙湾县| 沙河市| 溧水县| 彩票| 南充市| 岚皋县| 临澧县| 台东县| 宝鸡市| 兴山县| 屏东县| 安福县| 山丹县| 白山市| 双峰县| 界首市| 两当县| 扬中市| 香格里拉县| 贵定县| 化德县| 蛟河市| 丹凤县| 门头沟区| 马鞍山市| 扶绥县| 子长县| 棋牌| 昔阳县| 铁岭县| 乐安县| 龙江县| 通化市| 正定县| 若羌县| 石棉县| 章丘市| 赫章县| 曲水县| 淄博市|