Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 角度2-我能';t从JSON(类型脚本)输出我的值_Angularjs_Angular_Typescript - Fatal编程技术网

Angularjs 角度2-我能';t从JSON(类型脚本)输出我的值

Angularjs 角度2-我能';t从JSON(类型脚本)输出我的值,angularjs,angular,typescript,Angularjs,Angular,Typescript,我试图在Angular 2中使用*ngFor输出一个列表,但真正在屏幕上显示内容的唯一方法是执行以下操作: <li *ngFor="let node of nodes">{{node | json}}</li> 以下是我的对象在控制台中的外观: 谢谢大家! 看起来您的响应对象具有类型数组的“标题”(array[1]),这就是您看到打印的[object]的原因。您可以尝试展开标题,并将其放入模板中 {{node.title."titiledummy"}} 从'@an

我试图在Angular 2中使用*ngFor输出一个列表,但真正在屏幕上显示内容的唯一方法是执行以下操作:

<li *ngFor="let node of nodes">{{node | json}}</li>
以下是我的对象在控制台中的外观:


谢谢大家!

看起来您的响应对象具有类型数组的“标题”(
array[1]
),这就是您看到打印的
[object]
的原因。您可以尝试展开
标题
,并将其放入模板中

{{node.title."titiledummy"}}

从'@angular/core'导入{Component,OnInit};
@组成部分({
选择器:“我的应用程序”,
模板:`{{node.title[0].key}}`
})
导出类AppComponent实现OnInit{
私有节点=[{title:“基本页面1”,内容:“Drupal8中的测试页面…”,{title:“基本页面2”,内容:“Drupal8中的另一页面…”];
构造函数(){
}
恩戈尼尼特(){
this.nodes=[{title:[{'key':“basic page 1”}],内容:“Drupal 8中的测试页…”,{title:[{'key':“basic page 2”}],内容:“Drupal 8中的另一页…”);
}

为什么你不想在Promise回调中解析JSON.parse(r)?我想我已经尝试过了,但我想我的经验不足以让它正常工作。如果你打印出{{node | JSON}会有什么结果?我得到了一个我的文章列表…但是是原始JSON…只是给你一个简短的例子,{{node.title | JSON}给我这个:[{“value”:“第二个测试页面”}][{“值”:“测试页面1”}]在标题下,我有另一个对象,在该对象下我有我想要的值…请参阅更新的图片刚刚发布了指向plunker的链接,带有工作示例
import { Component, OnInit } from '@angular/core';
import 'rxjs/add/operator/toPromise';
import { Injectable } from '@angular/core';
import {Http, Headers, Response} from '@angular/http';


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


export class AppComponent implements OnInit{

  getData: string;
  postData: string;
  nodes = [{title : "basic page 1", content: "test page in Drupal 8 ..."}, {title : "basic page 2", content: "Another page in Drupal 8 ..."}];

constructor(private http: Http) {
}

ngOnInit() {

    this.http.get("http://the-server.co.uk/rest/export/json/basic").
        toPromise().then(r => r.json()).then(r => this.nodes = r);
        }
}
{{node.title."titiledummy"}}
import { Component, OnInit } from '@angular/core';


@Component({
  selector: 'my-app',
  template: `<li *ngFor="let node of nodes">{{node.title[0].key}}</li>`
})


export class AppComponent implements OnInit{

  private nodes = [{title : "basic page 1", content: "test page in Drupal 8 ..."}, {title : "basic page 2", content: "Another page in Drupal 8 ..."}];

constructor() {
}

ngOnInit() {
this.nodes = [{title : [{'key':"basic page 1"}], content: "test page in Drupal 8 ..."}, {title : [{'key':"basic page 2"}], content: "Another page in Drupal 8 ..."}];

}