【发布时间】:2016-05-23 20:16:36
【问题描述】:
在 Angular 2 中,我有一个组件订阅返回模型的服务,然后使用 JsonPipe 在
我的代码(假设有正确填充模型的服务):
/* example.ts */
export interface Example {
id: number;
description: string;
}
/* example.component.ts */
export class ExampleComponent {
public example: Object = Object;
constructor(private _exampleService: ExampleService) {
this._getExample();
}
private _getExample() {
this._exampleService
.getExample()
.subscribe(example => this.example = <Example> example);
}
}
/* example.template.ts */
<form>
Description: <textarea>{{example.description | json}}</textarea>
</form>
这将呈现一个如下所示的
_______________________________
Description: | "this is the description" |
‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
引号没有理由围绕字符串。怎么回事?
【问题讨论】:
-
尝试
asych管道而不是json管道。请注意,asych管道将为您提供subscribe()。
标签: angularjs angular angular2-template