一 父组件

company.component.ts

import { Component, OnInit } from '@angular/core';

@Component({
selector: 'app-company',
templateUrl: './company.component.html',
styleUrls: ['./company.component.css']
})
export class CompanyComponent implements OnInit { employee = 'Tom';
skill: string; constructor() { } ngOnInit() {
} releaseSkill(skill: string) {
this.skill = skill;
} }

company.compnent.html

<p>
company works! {{skill}}
</p>
<app-employee [name]="employee" (releaseSkill)="releaseSkill($event);"></app-employee>

二 子组件

employee.component.ts

import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';

@Component({
selector: 'app-employee',
templateUrl: './employee.component.html',
styleUrls: ['./employee.component.css']
})
export class EmployeeComponent implements OnInit { @Input()
name: string; skill: string; @Output()
releaseSkill: EventEmitter<string> = new EventEmitter(); constructor() { } ngOnInit() {
} perform() {
this.skill = '摄影';
this.releaseSkill.emit(this.skill);
} }

employee.component.html

<p>
employee works! {{name}}
</p>
<button type="button" (click)="perform();">表演</button>

三 运行效果

Angular之输入输出属性的更多相关文章

  1. angular $http配置属性

    $http请求的配置对象 $http()接受的配置对象可以包含以下属性: method:http请求方式,可以为GET,DELETE,HEAD,JSONP,POST,PUT url:字符串,请求的目标 ...

  2. angular 2+ innerHTML属性中内联样式丢失

    通过属性绑定的innerHTML,把字符串里面的html解析 解析是没问题的,但一些内联样式会丢失掉 为了不丢掉样式,需要自定义一个管道来解决这个问题 html.pipe.ts import {Pip ...

  3. angular中datetime-local属性使用ng-model报错

    项目需求是将年月日格式更改为年月日时分的格式展示,翻遍了整个项目没找到符合的组件,自己现敲一个也来不及,只好直接使用原生自带的组件--datetime-local.之前都是用的vue写项目,第一次接触 ...

  4. 在checkbox中使用.prop; angular中属性的值使用变量问题

    1.在checkbox中使用.prop而不使用.attr ,.attr有时并不如愿的改变checkbox的打钩问题 给这个checkbox设置return  false就能阻止点击则改变状态的默认行为 ...

  5. {{angular.js 使用技巧}} - 实现计算列属性

    前端MV*框架现在有很多,其中某些框架有计算列(又叫监控属性),比如:微软推荐的 Knockout.js 和博客园司徒正美的 avalon.js 框架. 本人只使用过 Knockout.js,aval ...

  6. Angular组件——父子组件通讯

    Angular组件间通讯 组件树,1号是根组件AppComponent. 组件之间松耦合,组件之间知道的越少越好. 组件4里面点击按钮,触发组件5的初始化逻辑. 传统做法:在按钮4的点击事件里调用组件 ...

  7. Angular 4.0从入门到实战

    AngularJS 优点 模板功能强大丰富,并且是声明式的,自带了丰富的Angular指令: 是一个比较完善的前端MVC框架,包含模板,数据双向绑定,路由,模块化,服务,过滤器,依赖注入等所有功能: ...

  8. Angular 5.x 学习笔记(1) - 模板语法

    Angular 5.x Template Syntax Learn Note Angular 5.x 模板语法学习笔记 标签(空格分隔): Angular Note on github.com 上手 ...

  9. Angular 学习思路

    近些年前端框架非常多,主流的有 Vue.React.Angular 等.我参与的项目中使用较多的是 Vue.因为 Vue 学习难度不大,上手很快,代码简洁,而且使用 Vue 全家桶(Vue + Vue ...

随机推荐

  1. 【Linux】CentOS7 安装,遇到的各种问题,并修复win7启动项

    https://www.cnblogs.com/sxdcgaq8080/p/7457255.html ------------------------------------------------- ...

  2. day12-集合

    集合 1.什么是集合 set(集合)是一个无序不重复元素的数据集,与列表的区别1.无序的,不可以使用索引进行顺序的访问2.不能够有重复的数据. 项目开发中,集合主要用在数据元素的去重和测试是否存在.集 ...

  3. AIR文件操作(二):使用文件对象操作文件和目录

    转载于:http://www.flashj.cn/wp/air-file-operation2.html 文件对象是啥?文件对象(File对象)是在文件系统中指向文件或目录的指针.由于安全原因,只在A ...

  4. MFC+OpenGL基础绘制<转>

    转载地址:https://blog.csdn.net/u013232740/article/details/47904115 ------------------------------------- ...

  5. JSP页面java代码报错:Purgoods cannot be resolved to a type

    错误提示 : Purgoods cannot be resolved to a type Purgoods不能解析为一个类型 原因 : 缺少引入Purgoods类 页面中引入java类,执行java代 ...

  6. newCachedThreadPool使用案例

    newCachedThreadPool 缓存默认60s 猜下你的结果 package com.juc.threadpool; import java.util.concurrent.ExecutorS ...

  7. SQL 用到的操作符

    1.LIKE 操作符用于在 WHERE 子句中搜索列中的指定模式. SELECT column_name(s) FROM table_name WHERE column_name LIKE patte ...

  8. Linux:服务器/客户端API调用错误检查

    昨天和今天上午,我分别实现简单的服务器和客户端,运行之后表示没问题,一切正常.但是这还是有问题的,最大的一个就是没有错误检查.现在我们来加上错误检查: 服务器的代码: #include <std ...

  9. git 合并多个commit

    1,查看提交历史,git log 首先你要知道自己想合并的是哪几个提交,可以使用git log命令来查看提交历史,假如最近4条历史如下: commit 3ca6ec340edc66df13423f36 ...

  10. 使用docker-compose创建启动容器时候提示服务名已存在

    今天在测试环境启动一个已有服务时候提示服务名已存在,造成这个原因是,前些天集群的一个节点挂了,导致这个节点上的docker容器全部没了,为了当时能正常使用就使用 docker-compose -H 1 ...