All Questions

24
votes
4answers
5750 views

How do I return the response from an Observable/http/async call in angular2?

I have service which returns an observable which does an http request to my server and gets the data. I want to use this data but I always end up getting undefined. What's the problem? Service: @Inj...
107
votes
9answers
76145 views

How can I use/create dynamic template to compile dynamic Component with Angular 2.0?

I want to dynamically create template. This should be used to build a ComponentType at Runtime and place (even replace) it somewhere inside of the hosting Component. Until RC4 I was using ComponentR...
89
votes
8answers
40346 views

Equivalent of $compile in Angular 2

I want to manually compile some HTML containing directives. What is the equivalent of $compile in Angular 2? For example, in Angular 1, I could dynamically compile a fragment of HTML and append it t...
412
votes
15answers
174251 views

Difference between Constructor and ngOnInit

Angular provides life cycle hook ngOnInit by default. Why should ngOnInit be used, if we already have a constructor?
150
votes
14answers
174245 views

How do I cast a JSON object to a typescript class

I read a JSON object from a remote REST server. This JSON object has all the properties of a typescript class (by design). How do I cast that received JSON object to a type var? I don't want to popul...
58
votes
5answers
52080 views

How do I share data between components in Angular 2?

In Angular 1.x.x you simply ask for the same service and you end up with the same instance, making it possible to share the data in the service. Now in Angular 2 I have a component that has a referen...
117
votes
12answers
122611 views

How do I initialize a TypeScript object with a JSON object

I receive a JSON object from an AJAX call to a REST server. This object has property names that match my TypeScript class (this is a follow-on to this question). What is the best way to initialize it...
222
votes
14answers
184494 views

typescript getting error TS2304: cannot find name ' require'

I am trying to get my first Typescript and DefinitelyTyped node app up and running, and running into some errors. I am getting the error "TS2304: Cannot find name 'require' " when I attempt to transp...
132
votes
8answers
61085 views

How do I use namespaces with TypeScript external modules?

I have some code: baseTypes.ts export module Living.Things { export class Animal { move() { /* ... */ } } export class Plant { photosynthesize() { /* ... */ } } } dog.ts import b ...
110
votes
10answers
55851 views

Expression ___ has changed after it was checked

Why is the component in this simple plunk @Component({ selector: 'my-app', template: `<div>I'm {{message}} </div>`, }) export class App { message:string = 'loading :('; ngAfterV...

Previous Next