I am following Angular's own main tutorial on setting up a Javascript project. This works fine, but it stops after 'hello world' and continues with Typescript.
Most typescript examples can be translated back to javascript and still work, but now I am stuck at making HTTP calls.
In index.html I load all modules as separate script files:
<script src="node_modules/@angular/http/bundles/http.umd.js"></script>
In app.module.js I load ng.http.HttpModule
and according to most answers here on stackoverflow, I need to include ng.http.HTTP_PROVIDERS
in the bootstrap part:
(function(app) {
app.AppModule =
ng.core.NgModule({
imports: [ ng.platformBrowser.BrowserModule, ng.forms.FormsModule, ng.http.HttpModule ],
declarations: [ app.AppComponent, app.Actorlist ],
bootstrap: [ app.AppComponent, [ng.http.HTTP_PROVIDERS] ]
})
.Class({
constructor: function() {}
});
})(window.app || (window.app = {}));
The HTTP_PROVIDERS part generates this error:
Unexpected value 'undefined' used in the bootstrap property of module 'class2'
If I leave that out I don't get an error, but I still can't call http from my component:
(function(app) {
app.Actorlist =
ng.core.Component({
selector: 'actor-list',
templateUrl: './app/actorlist.component.html'
})
.Class({
constructor: function() {
},
searchActor: function(){
var result = this.getActor();
console.log(result);
},
getActor: function(){
return ng.http.get(this.url)
.map(function (response) {
return response.json().data;
})
.catch();
}
});
})(window.app || (window.app = {}));
This results in the error:
Error in app/actorlist.component.html:2:0 caused by: ng.http.get is not a function
How do I get the http reference into my component?