学习了这些概念就能简单的描述一个选项功能的选项卡按钮:

数据:
1.数组:
实例化一个数组的类,如果想要使用这个类中的数据,需要在组件中 使用一个公共属性来暴漏这个类如 heroes=HEROES;
const 数组名HEROES:数组中数据结构=[
    
]

命令指令
1.*ngFor="let value of arr/json"   ==>  {{value}}
2.(click)=函数名(参数)

angular的模块    模板语法:https://www.angular.cn/docs/ts/latest/guide/template-syntax.html#!#ngModel
1.表单元素支持双向绑定:FormsModule  from '@angular/forms'  
    在impors入口中添加:FormsModule  模块
    使用:  <input [(ngModel)]="hero.name" placeholder="name">
    在页面中的模块中添加   hero的数据   ,使数据和输入框中  ngModel 产生关联

app.component.ts文件:

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

export class Title{
id:number;
name:string;
} const TITLE:Title[]=[
{id:1,name:'体育'},
{id:2,name:'艺术'},
{id:3,name:'旅行'}
] @Component({
selector: 'my-app',
template: `
<section id='div' class="box">
<img src="app/images/01.png" alt="" class="bg_index">
<section id='div1'>
<a href="javascript:;" class="back"></a>
<ul class="clearfix" id="box">
<!--这里面做了三件事,ngFor循环创建li,[ngClass]动态的输出添加类名,(click)在点击的时候输出当前li的id并动态的赋予curId值-->
<li *ngFor="let title of titles" [ngClass]="(curId == this.title.id) ?'active':''" (click)="forActive(this.title.id)">{{title.name}}</li>
</ul>
<img class="poem" src="app/images/02.png" alt="">
</section>
</section>
`,
styles:[`
#div{
width:100%;
height:100%;
}
#div1{
overflow: hidden;
}
.bg_index{
width:100%;
height:100%;
position:fixed;
left:0;
top:0;
z-index:-1;
}
.back{
display:block;
width:0.77rem;
height:0.77rem;
background:url("app/images/04.png") no-repeat;
background-size:contain;
margin-top:0.5rem;
margin-left:0.3rem;
}
#box{
padding-left:5%;
margin-top:25%;
width: 100%;
height: 7rem;
}
#box li{
font:bold 0.6rem '微软雅黑';
text-align:center;
height:70%;
margin-top:0.4rem;
width: 30%;
line-height: 1rem;
float:left;
color:rgba(255,255,255,.5);
}
#box .active{
color:rgba(255,255,255,1);
}
.poem{
width:0.85rem;
height:0.85rem;
position:fixed;
bottom:0.35rem;
left:50%;
margin-left:-0.425rem;
}
`]
})
export class AppComponent {
titles=TITLE;
//设置默认选中选项
curId :number =2;
//点击切换选项函数
forActive(n1:number):void{
this.curId = n1;
}
}

angular2自学笔记(三)---ng2选项卡的更多相关文章

  1. angular2自学笔记---官网项目(一)

    1.单向数据绑定的'插值表达式' angular中最典型的数据显示方式:把HTML模板(template)的控件绑定到angular组件的属性(component相当于一个构造函数,下面例子中的这个构 ...

  2. angular2自学笔记(二)---路由、服务等八大主要构造块

    angular的思想:总是把数据访问工作委托给一个支持性服务类. Angular 应用的:用 Angular 扩展语法编写 HTML 模板, 用组件类管理这些模板,用服务添加应用逻辑, 用模块打包发布 ...

  3. webpack4 自学笔记三(提取公用代码)

    全部的代码及笔记都可以在我的github上查看, 欢迎star:https://github.com/Jasonwang911/webpackStudyInit/tree/master/commonT ...

  4. 【C++初学者自学笔记三】哑元函数、缺省参数、内联函数(模块二,PS:需要用到重载函数)

    一,哑元函数:一个函数的参数只有类型没有名字的则这个参数称之为哑元.类似于void fun(int); 功能:1保持向前的兼容性,比方说我们需要做成一个成品,然后成品是会不断的更新第一代第二代,当我们 ...

  5. vue 自学笔记(三) 计算属性与侦听器

    一:计算属性 虽然在模板内使用表达式对属性进行处理十分便利,例如在小胡子语法里写number + 1实现对数据的简单处理,但若我们在其中加入大量的代码,使得逻辑变重,导致难以维护.例如下面的代码,并不 ...

  6. vue 自学笔记记录

    vue 自学笔记(一): 知识内容:  安装vue ,创建vue实例,安装第一个组件,单项数据流 https://www.cnblogs.com/baili-luoyun/p/10763163.htm ...

  7. 《Linux内核设计与实现》课本第三章自学笔记——20135203齐岳

    <Linux内核设计与实现>课本第三章自学笔记 进程管理 By20135203齐岳 进程 进程:处于执行期的程序.包括代码段和打开的文件.挂起的信号.内核内部数据.处理器状态一个或多个具有 ...

  8. python自学笔记

    python自学笔记 python自学笔记 1.输出 2.输入 3.零碎 4.数据结构 4.1 list 类比于java中的数组 4.2 tuple 元祖 5.条件判断和循环 5.1 条件判断 5.2 ...

  9. ssh自学笔记

    Ssh自学笔记 Ssh简介 传统的网络服务程序,如:ftp.pop和telnet在本质上都是不安全的,因为它们在网络上用明文传送口令和数据,别有用心的人非常容易就可以截获这些口令和数据.而且,这些服务 ...

随机推荐

  1. [JS&Jquery]实现页面表格中相同内容的行或列合并

    详细链接:https://shop499704308.taobao.com/?spm=a1z38n.10677092.card.11.594c1debsAGeak<script type=&qu ...

  2. 【C#】在datatable中添加一序号列,编号从1依次递增,并且在第一列

    详细链接:https://shop499704308.taobao.com/?spm=a1z38n.10677092.card.11.594c1debsAGeak/// <summary> ...

  3. ({i:0#.w|nt authority\iusr})Sharepoint impersonates the IUSR account and is denied access to resources

    This hotfix makes a new application setting available in ASP.NET 2.0. The new application setting is ...

  4. hibernate SQL Error: 8152, SQLState: 22001

    这种会出现字符串截断 数据库字段长度设置太小,改大即可.

  5. Android 屏幕适应

    基础知识: 屏幕密度: Density-independent pixel (dp):密度无关像素单位(一个相对的值).1dp 的大小相当于一个 160 dpi 屏幕上一个像素的大小. 计算方法:px ...

  6. ceph luminous 新功能之内置 dashboard

    # 开启 dashboard (在任一 mon_server 节点上)ceph mgr module enable dashboard # 设置dashboard 端口和IPceph config-k ...

  7. 关于iframe切换的问题

    定位不到元素的另一种问题是有这种iframe,所有我们需要切换到该页面中去 1.首先找到这个iframe的位置,像上图有id属性我们直接  iframe = driver.find_element_b ...

  8. Flink--Streaming Connectors

    原网址:https://ci.apache.org/projects/flink/flink-docs-release-1.7/dev/connectors/ Predefined Sources a ...

  9. 钉钉机器人集成Jenkins推送消息模板自定义发送报告

    一.由于公司同样也使用了钉钉.那么在做Jenkins集成自动化部署的时候,也是可以集成钉钉的. 那种Jenkins下载钉钉插件集成,简单设置就可以完成了.我们今天要做的是,定制化的发送消息. 钉钉推送 ...

  10. shell-009:删除字母

    把一个文件里的前100行中有字母的行删除:再把101-200行的字母去掉 #!bin/bashsed '101.200s/[a-zA-Z]//g' filesed -n '1.100'p file | ...