打赏

angular 服务

1. 创建 ng g s service/list

 

2.在app.module.ts中引入

import { ListService } from './service/list.service';
@NgModule({
  ...
  providers: [ListService],
})

  

 
3.在组件中使用
import { ListService } from 'src/app/service/list.service';


 list:Array<string> = [];

  constructor(private listService:ListService=new ListService() ) { }


  ngOnInit(): void {
    this.list = this.listService.getList();
  }

  clickHandle(){
    this.listService.addList('node.js')
  
  }

  

 
 
 
 
 

posted on 2024-03-24 14:10  jlyuan  阅读(4)  评论(0编辑  收藏  举报

导航