1.在组件下面新建一个data.ts文件,将数据放进去
var cartList:object[]= (数据)export default cartList; //导出一下
2.在要使用数据的组件的.ts文件中导入data.ts
import { Component, OnInit } from '@angular/core';import cartList from './data'; //导入...export class HeaderComponent implements OnInit {public msg:string='hello world';public checked:boolean=true;public cartList:any=cartList; //定义数据类型constructor() {console.log(cartList) //可以打印看一下有没有}...}
3..html页面使用
<div *ngFor="let item of cartList">{{item.productName}}</div>
