TypeScript接口学习心得之一
import { Component, OnInit } from ‘@angular/core‘;
import { ActivatedRoute } from ‘@angular/router‘;
import { MyObj } from ‘src/app/pojo/myObj‘;
@Component({
selector: ‘app-work‘,
templateUrl: ‘./work.component.html‘,
styleUrls: [‘./work.component.css‘]
})
export class WorkComponent implements OnInit {
constructor(private route: ActivatedRoute) { }
//我们传入的对象参数实际上包含了很多属性,
//但是类型检查器不会去检查属性的顺序
//只会检查那些必需的属性是否存在
public my={ size:10,label:"hello world",name:‘zhangsan‘}; //属性顺序跟接口定义的顺序不一致
ngOnInit() {
this.pritntLable(this.my);
}
pritntLable(obj: MyObj){
console.log(obj.label);
}
}
相关推荐
changcongying 2020-11-02
changcongying 2020-10-30
苗疆三刀的随手记 2020-10-29
zouph000 2020-10-25
Jruing 2020-10-23
ctg 2020-10-14
PMJ0 2020-10-13
ChaITSimpleLove 2020-10-06
小飞侠V 2020-09-25
QiaoranC 2020-09-25
changcongying 2020-09-17
taizuduojie 2020-09-15
淼寒儿 2020-09-13
lyjava 2020-09-11
彤庆的技术 2020-09-02
锅哥 2020-08-27
ruanhongbiao 2020-08-16
zouph000 2020-08-03
Java编程语言学习 2020-07-29