javascript - how to create a component that i can set fetching url data in an attribute in angular 2 -


i'm trying create application angular 2 , want create component in angular 2 set url in attribute , want use several times component , each component have own data... want : possible or not?

i'll appreciate if me.

new movies :  <comp url="www.aaaa.com/movies?type=new"></comp>  old movies :  <comp url="www.aaaa.com/movies?type=old"></comp> 

@component({   selector: 'comp',   template: '<div>{{data}}</div>' }) export class component {   @input() url: string;   constructor(private http:http) {   }    ngonchanges(changes) {     this.http.get(this.url)     .map(res => res.json())     .subscribe(val => this.data = val);   }  } 

if component has more 1 input need check 1 updated. see https://angular.io/api/core/onchanges more details.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -