Javascript 知足的+;角2

Javascript 知足的+;角2,javascript,angular,angular2-services,contentful,Javascript,Angular,Angular2 Services,Contentful,嗨,我正在尝试使用Contentful和Angular2,并使用Contentful交付API 例如,我可以获得特定的数据 知足的服务 HomePage() { return this.http .get('https://cdn.contentful.com/spaces/PRIVATE/entries?access_token=PRIVATE&sys.id=PRIVATE') .map((res:Response)

嗨,我正在尝试使用Contentful和Angular2,并使用Contentful交付API

例如,我可以获得特定的数据

知足的服务

HomePage() {              
    return this.http
        .get('https://cdn.contentful.com/spaces/PRIVATE/entries?access_token=PRIVATE&sys.id=PRIVATE')
        .map((res:Response) => res.json());    /* map response to var */  
}
homepage.component.ts

export class Home {

pagename: string;

    ngOnInit() {

        this.http.HomePage()
           .subscribe( 
               data => {
                       this.pagename = data.items[0].fields.pageName;
               }
          );
    }
 }
但是,如果我有多个项,我需要将每个data.item声明为一个字符串,这将非常冗长。然后,如果我决定向内容类型添加一个新字段,这可能会添加到数组的中间,这样就破坏了当前的绑定,并且需要再次更新它们。 我见过另一个回购协议,他们在模板中使用了我正在寻找的架构,我知道这是做我需要做的事情的正确方法

e、 g.homepage.template.html

<ul contentful-entries="'content_type=dog&limit=10'">
  <li ng-repeat="dog in $contentfulEntries.items">
    {{ dog.fields.name }}
  </li>
</ul>
我假设通过查找您需要的项目的ID,然后查找任何关系,您会得到资产的ID,然后查找资产?但这又是通过SDK实现的吗?还是我需要写这个代码

我迷路了


非常感谢您的帮助,谢谢

我在Contoful工作,负责JS SDK

我在这里看到了一些解决方案:

  • 您可以按照我们构建的示例继续,它构建在Angular的基础上,您可能还需要更新依赖项等。。。如果您需要任何帮助,请随意在此处创建问题

  • 使用ngUpgrade,您可以使Angular 1模块在Angular 2上运行,反之亦然,并提供更多信息。这是一个快速而肮脏的解决方案

  • 您可以将代码分叉并进行检查

  • 您可以使用contenful.js SDK并将其包装到服务中,在那里您将获得链接解析等。。。然后填充视图

  • 我现在无法向您提供示例代码,但我们正在使用Angular 2和其他框架进行示例项目

    请注意,您提到的回购协议并非由Contentful正式维护

    最好的,
    哈立德

    嘿,这方面有什么更新吗?现在有什么例子吗?有一个关于如何做到这一点的教程
     {
      "sys": {
          "type": "Array"
      },
      "total": 1,
      "skip": 0,
      "limit": 100,
      "items": [
         {
            "sys": {
                "space": {
                "sys": {
                "type": "Link",
                "linkType": "Space",
                "id": "1ST_UNIQUE_ID"
            }
        },
        "id": "2ND_UNIQUE_ID",
        "type": "Entry",
        "createdAt": "2016-07-14T16:30:12.787Z",
        "updatedAt": "2016-07-14T16:30:12.787Z",
        "revision": 1,
        "contentType": {
          "sys": {
            "type": "Link",
            "linkType": "ContentType",
            "id": "pressRelease"
          }
        },
        "locale": "en-US"
      },
      "fields": {
        "title": "Title of Review",
        "excerpt": "Excerpt of review",
        "content": "Content of Review",
        "dateCreated": "2016-07-01",
        "datePublished": "2016-07-14",
        "featureImage": {
          "sys": {
            "type": "Link",
            "linkType": "Asset",
            "id": "3RD_UNIQUE_ID"
          }
        }
      }
    }
    ],
    "includes": {
        "Asset": [
           {
             "sys": {
             "space": {
             "sys": {
                 "type": "Link",
                 "linkType": "Space",
                 "id": "1ST_UNIQUE_ID"
             }
           },
           "id": "4TH_UNIQUE_ID",
           "type": "Asset",
           "createdAt": "2016-07-14T16:30:05.078Z",
           "updatedAt": "2016-07-14T16:30:05.078Z",
           "revision": 1,
           "locale": "en-US"
        },
        "fields": {
          "title": "Image Title",
          "description": "Image Description",
          "file": {
            "url": "//url-of-image.jpg",
            "details": {
              "size": 43098,
              "image": {
                "width": 1278,
                "height": 928
              }
            },
            "fileName": "image.jpg",
            "contentType": "image/jpeg"
          }
        }
      }
      ]
     }
     }