由于组件之间难以通用,故可以调用服务
1. 新建服务器
ng g service Service/storage
2. 引入服务
import { StorageService } from '../Service/storage.service'
3. 初始化
constructor(public storage:StorageService) {
let s = this.storage.get();
console.log(s);
}
由于组件之间难以通用,故可以调用服务
1. 新建服务器
ng g service Service/storage
2. 引入服务
import { StorageService } from '../Service/storage.service'
3. 初始化
constructor(public storage:StorageService) {
let s = this.storage.get();
console.log(s);
}