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);
}
}
原文地址:https://www.cnblogs.com/kukai/p/12181241.html
时间: 2024-10-20 07:13:58