2017-08-06 77 views
0

Angular2模块组件给我错误管道无法找到Angular2模块组件给我错误管道无法找到

{{obj|json}}

管道JSON找不到。 错误的可能原因是什么?

+0

这是否帮助? https://stackoverflow.com/questions/40389309/json-pipe-in​​-angular-2-is-not-working – animsaj

+0

我读过它,并试过它,但它不工作。 –

回答

0

下面是测试代码,它只是工作:

app.component.ts

import { Component } from '@angular/core'; 

@Component({ 
selector: 'app-root', 
templateUrl: './app.component.html', 
styleUrls: ['./app.component.css'] 
}) 
export class AppComponent { 

    obj : any = ['test1', 'test2', 'test3']; 

} 

app.component.html

{{ obj | json }} 

浏览器输出

[“ test1“,”test2“,”test3“]

您可以在此处粘贴代码,以便我们可以检查管道上的缺失位置。

你可以在这里检查Jsonpipe更多信息

https://angular.io/api/common/JsonPipe

+0

我在我的项目中有两个模块,它在一个模块的组件中工作正常,但它不在其他模块的组件中工作。 –

+0

你可以粘贴你的代码在这里或在蹲,所以检查可能的错误? –

+0

我发现我在第三个模块中使用组件,并且该模块没有CommonModule,并且它创建了问题。感谢它现在正在工作, –

相关问题