码迷,mamicode.com
首页 > 其他好文 > 详细

TypeScript接口学习心得之一

时间:2020-01-11 22:33:46      阅读:96      评论:0      收藏:0      [点我收藏+]

标签:col   type   ted   private   ons   mic   struct   name   back   

 技术图片

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

TypeScript接口学习心得之一

标签:col   type   ted   private   ons   mic   struct   name   back   

原文地址:https://www.cnblogs.com/kukai/p/12181241.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!