【发布时间】:2015-10-11 17:10:56
【问题描述】:
下面是我的控制器和 html:当我在控制器中调用 make api 时,我将结果存储在结果变量中,现在,当我尝试在 html 中打印时,结果变量没有打印任何内容,我已经使用了另一个当我打印它时,控制器中的变量名在 html 中打印。但是当我尝试在控制器中打印结果变量时,它正在控制台中打印数据。所以,我正确地获取了变量中的数据。但是,为什么它不在 html 中打印。请帮忙。
控制器:
module typescript {
var my_app = angular.module('my_app', []);
export class test {
public name: any;
constructor(private $http: ng.IHttpService) {
this.name = "Test data";
this.getdata();
}
getdata() {
return this.$http.get('facilities.json').success(function(response) {
this.result = response;
console.log(this.result);
})
}
}
test.$inject = ['$http'];
myapp.controller("test", test);
}
任何帮助将不胜感激。
【问题讨论】:
-
{{test1.result}}{{test1 .name}}
-
使用 Typescript 你可以使用'static $inject = ['$http'];'在你的班级内,而不是用它来扩展班级。把它放在构造函数的正上方。
标签: angularjs typescript