admin管理员组文章数量:1401620
I'm new to Typescript and HTML. I'm building an Angular2 app and I currently have a TypeScript file that looks like this:
import {Http, Headers} from 'angular2/http';
import {Component} from 'angular2/core';
import {CORE_DIRECTIVES, FORM_DIRECTIVES} from 'angular2/mon';
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";
}
}
I'm trying to figure out how to get the value for "jsonResponse" in an HTML file. I've searched but can't find a straightforward way to access the jsonResponse variable - any ideas?
I'm new to Typescript and HTML. I'm building an Angular2 app and I currently have a TypeScript file that looks like this:
import {Http, Headers} from 'angular2/http';
import {Component} from 'angular2/core';
import {CORE_DIRECTIVES, FORM_DIRECTIVES} from 'angular2/mon';
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";
}
}
I'm trying to figure out how to get the value for "jsonResponse" in an HTML file. I've searched but can't find a straightforward way to access the jsonResponse variable - any ideas?
Share Improve this question asked May 12, 2016 at 23:19 Roka545Roka545 3,63623 gold badges70 silver badges111 bronze badges 2- Do you just want to display the value of jsonResponse on the page? – sourdoughdetzel Commented May 12, 2016 at 23:34
- Put this {{jsonResponse}} in your html page – Som Commented May 13, 2016 at 0:01
2 Answers
Reset to default 2Here is what you are looking for: link to working code: 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';
};
}
There is also the json
pipe
{{jsonResponse | json}}
本文标签: javascriptGet value from TypeScript (ts) in HTML fileStack Overflow
版权声明:本文标题:javascript - Get value from TypeScript (.ts) in HTML file. - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744313895a2600165.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论