[Angular Directive] 2. Add Inputs to Angular 2 Directives
The @Input
decorator allows you to pass values into your @Directive
so that you can change the value of the Directive each time that it is used. Using @Input
makes your Directives much more flexible and reusable so they can adapt to many different situations.
import {Directive, Input, HostBinding} from '@angular/core'; @Directive({
selector: '[getInput]'
})
export class GetInputDirective { @Input('getInput') input;
@HostBinding() get innerText() {
return this.input;
}
constructor() { } }
<span [getInput]="'something'">I am a span</span>
[getInput] means we have a prop on our directive call 'getInput', go and find it and set the value as 'something'.
It will only show "something" on the page. Here we pass value to the directive, then reflect the input value to the Host element's innerText by using getter.
[Angular Directive] 2. Add Inputs to Angular 2 Directives的更多相关文章
- [Angular Directive] 3. Handle Events with Angular 2 Directives
A @Directive can also listen to events on their host element using @HostListener. This allows you to ...
- angular directive scope
angular directive scope 1.当directive 中不指定scope属性,则该directive 直接使用 app 的scope: 2.当directive 中指定scope属 ...
- [Angular Directive] Assign a Structual Directive a Dynamic Context in Angular 2
Just like passing in an array to *ngFor, you can pass in any value into your structural directive s ...
- [Angular Directive] Implement Structural Directive Data Binding with Context in Angular
Just like in *ngFor, you're able to pass in data into your own structural directives. This is done b ...
- Angular项目构建指南 - 不再为angular构建而犹豫不决(转)
如果你不知道什么是Angular或者根本没听说过,那么我接下来所说的对你来说毫无益处,不过如果你打算以后会接触Angular或者干脆要涨涨姿势~读下去还是有点用的. Angular和它之前所出现的其余 ...
- [Angular 2 Router] Configure Your First Angular 2 Route
Using the Angular 2 router requires defining routes, passing them in to the RouterModule.forRoot and ...
- 【Angular专题】——(1)Angular,孤傲的变革者
目录 一. 漫谈Angular 二. 如果你还在使用Angularjs 三. 我计划这样学习Angular技术栈 一. 漫谈Angular Angular,来自Google的前端SPA框架,与Reac ...
- [Angular] Use Angular components in AngularJS applications with Angular Elements
When migrating AngularJS (v1.x) applications to Angular you have different options. Using Angular El ...
- Angular 从入坑到挖坑 - Angular 使用入门
一.Overview angular 入坑记录的笔记第一篇,完成开发环境的搭建,以及如何通过 angular cli 来创建第一个 angular 应用.入坑一个多星期,通过学习官方文档以及手摸手的按 ...
随机推荐
- JavaScript--Module模式
//module: Module模式是JavaScript编程中一个非常通用的模式 window.onload = function() { //1.基本使用: var MyFn = function ...
- JavaScript的字符串、数组以及DOM操作总结
(一)JavaScript字符串操作 JavaScript的字符串就是用' '或" "括起来的字符表示,日常的学习中有时候需要对字符串进行相关的操作.例如要获取字符串某个指定位置的 ...
- Linux下改动Oracle数据库字符集命令
常见情形:从server备份Oracle数据库后再到本地机器上还原Oracle数据库的时候常常会碰见数据库字符编码不一致的情况,能够用下面命令来改动本地的Oracle数据库字符编码,然后顺利还原Ora ...
- h5背景
1.背景属性复习: background-image background-color background-repeat background-position background-attachm ...
- angular反向代理
第一步:根目录新建 proxy.conf.json target:就是代理的服务器地址. 接口地址必须是http://localhost:8081/api开头 { "/api":{ ...
- MySQL和SqlServer的区别
一.查看表结构数量等mysql语句: -- 查看系统内所有数据库 show databases: -- 查询数据库内所有表 show tables; -- 显示表结构 desc 表名; sql ser ...
- Mine Vison base on VC++ and procilica Gige Vison SDK
This is my first vision base on VC++6.0. I am so happy to record this time i succesfully create it b ...
- 【Codeforces Round #431 (Div. 2) C】From Y to Y
[链接]点击打开链接 [题意] 让你构造一个大小最多为10W的字符multiset. 你进行n-1次操作; 每次操作,从set中取出两个字符串,一开始单个字符被认为是字符串. 然后把它们连接在一起. ...
- cocos2d-x 3.0 游戏关卡滑动 弹动 不会出现黑边效果
#pragma once #include "cocos2d.h" #include "ShopScene.h" using namespace cocos2d ...
- Day2:字典
一.定义 字典是一种“key-value”成对出现的数据类型,中间用冒号把key与value隔,不同的数据用逗号隔开,全部数据用大括号括起来 info = { 'stu1101': "Ten ...