angular例子之ngFOr
发布时间:2020-12-17 08:50:03 所属栏目:安全 来源:网络整理
导读:html: h1 {{'this is title' | titlecase}}//管道怎么用?未知/h1div *ngIf="users.length 0; else empty" ul li *ngFor="let u of users; count as totalCount; index as i;"//命名挺规范滴,应该可以猜出来作用吧 User123 {{i}} of {{totalCount}}---{{u.
html: <h1> {{'this is title' | titlecase}}//管道怎么用?未知 </h1> <div *ngIf="users.length > 0; else empty"> <ul> <li *ngFor="let u of users; count as totalCount; index as i;">//命名挺规范滴,应该可以猜出来作用吧 User123 {{i}} of {{totalCount}}---{{u.name}}--{{u.content}} </li> </ul> </div> <ng-template #empty> //else:上面对应 There is no user </ng-template> <button (click)="addUser();">Add</button> <button (click)="deleteUser();">Delete</button> ts: import {Component,OnInit} from '@angular/core'; import {Meta} from '@angular/platform-browser'; @Component({ selector: 'app-root',templateUrl: './app.component.html',styleUrls: ['./app.component.css'] }) export class AppComponent implements OnInit { users; constructor(private meta:Meta){ } ngOnInit() { this.users = []; this.meta.addTag({//给meta也就是users添加数据 name:"author",content:"Allen" }) } addUser(){ this.users.push({ //添加方法 name:"mjx",content:"mamamama" }); this.meta.updateTag({//我猜:刷新name为author后来删除了 界面没有报错,换了一个浏览器界面还是没有问题,这就郁闷了,是我不会搜吗 name:"author",content:"Allen2" }) } deleteUser(){ this.users.shift(); } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- angular – 是否可以在Typescript中按值“过滤”
- angularjs – 如何使用角度ui-router验证状态
- bootstrap-datetimepicker.js的兼容性问题(IE10
- BOOTSTRAP简易使用指南
- scala – Spark:Executor Lost Failure(添加gro
- twitter-bootstrap – 如何使用yarn来安装bootst
- 斯卡拉 – 阿卡未来 – 并行与并发?
- loadrunner 11.0测试.net框架下的webservice.
- Angular 2 RC2新表格
- twitter-bootstrap – Bootstrap 3 glyphicons在
热点阅读