To set up a new project in angular
Download the angular code:npm install -g @angular/cli
install the project
ng new project_name
ng serve --open --port 42001
ng generate component home
ng generate service hero
Add Bootstarp 4 in Angular 7
1- npm install bootstrap --save2- Add css in angular.json file in styles array key ( "node_modules/bootstrap/dist/css/bootstrap.min.css" )
3- Hit ng serve
Download and run Angular Project in local machie:
git clone https://github.com/angular/quickstart.git quickstart
npm install (It will download the required modules according to the package.json)
npm start or ng serve
here , http client return data in the form of observables to use it we use the subscribe function, subscribe function comes with data so here,
(data:Topmenu[])
data in the form of Topmenu array , and then assign the data to the this.menus
now menus will use as an array in the html file,
Live reload not working when change code, then use
sudo ng serve --port 4203How to use Subscribe in angular when deal with http client with GET/POST
menus: Topmenu[] = [];
constructor( private TopmenuService:TopmenuService) { }
ngOnInit() {
this.getHeaderMenus();
}
getHeaderMenus(): void {
console.log('fire function');
this.TopmenuService.getHeaderMenus()
.subscribe(
(data:Topmenu[]) => this.menus = data
);
}
here , http client return data in the form of observables to use it we use the subscribe function, subscribe function comes with data so here,
(data:Topmenu[])
data in the form of Topmenu array , and then assign the data to the this.menus
now menus will use as an array in the html file,
Comments
Post a Comment