从HTML文件中的TypeScript(.ts)获取值
Get value from TypeScript (.ts) in HTML file.
我是Typescript和HTML的新手。我正在构建一个Angular2应用程序,目前我有一个TypeScript文件,如下所示:
import {Http, Headers} from 'angular2/http';
import {Component} from 'angular2/core';
import {CORE_DIRECTIVES, FORM_DIRECTIVES} from 'angular2/common';
import {Router} from 'angular2/router';
import {Routes} from '../routes.config';
@Component({
selector: 'home',
templateUrl: './app/home/home.html',
directives: [CORE_DIRECTIVES, FORM_DIRECTIVES]
})
export class Home {
public jsonResponse: string = "";
constructor(private _http: Http) {
var thisReference = this;
thisReference.getSensors();
}
getSensors() {
this.jsonResponse = "testResponse";
}
}
我正试图弄清楚如何在HTML文件中获得"jsonResponse"的值。我已经搜索过了,但找不到访问jsonResponse变量的简单方法——有什么想法吗?
以下是您要查找的内容:工作代码链接:https://plnkr.co/edit/Y6TeraRZT2NDnHMRB9B0?p=info
import {Component} from '@angular/core'
@Component({
selector: 'my-app',
providers: [],
template: `
<div>
<h2>jsonResponse: {{jsonResponse}}</h2>
</div>
`,
directives: []
})
export class App {
jsonResponse: string;
constructor(){
this.getSensors();
}
private getSensors() {
this.jsonResponse = 'testResponse';
};
}
还有json
管道
{{jsonResponse | json}}
相关文章:
- 使用 jQuery 的 .on 函数如何获取事件的原始元素
- jquery试图按名称获取按钮位置
- 如何在jQuery中获取元素的形式
- 如何在php文件中获取$.post-ajax传递的值
- 在Shopify中获取博客文章的图片
- 使用Javascript获取所选选项ID
- 在jQuery中获取表的行索引
- 使用jquery将mysql数据获取到新的表行中
- 在动态创建的元素上获取对特定选择器的引用
- 从城市名称获取惊喜
- Angular只从数组中获取所需的数据
- 无法将数据从firebase获取到我的html页面
- 从ajax请求中获取javascript对象
- 如何从画布上的某个移动事件中获取X和Y
- 是否有一个JS/jQuery函数可以获取某个类的每个元素的ID
- 如何在PHP中使用$_POST获取Select元素值
- 获取@ResponseBody的一部分作为主干和Spring MVC控制器之间的参数
- 从HTML文件中的TypeScript(.ts)获取值
- 如何更改选择组件'使用Knockout从JS(TS)中获取s值
- 获取Angular 2.ts文件,而不是.d.ts文件