加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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();
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读