小编And*_*esi的帖子

在ngOnInit promise中数组推送后,Angular 2不刷新视图

我创建了一个带有角度2的NativeScript应用程序,我有一个对象数组,我期望在应用程序的前端看到.行为是,如果我直接在ngOnInit()内部将对象推入数组,它可以工作,但如果我在ngOnInit()中创建一个承诺它不起作用.这是代码:

export class DashboardComponent {
     stories: Story[] = [];

     pushArray() {
         let story:Story = new Story(1,1,"ASD", "pushed");
         this.stories.push(story);
     }

     ngOnInit() {
         this.pushArray(); //this is shown

         var promise = new Promise((resolve)=>{
             resolve(42);
             console.log("promise hit");
         });

         promise.then(x=> {
             this.pushArray(); //this is NOT shown
         });
     }
 }
Run Code Online (Sandbox Code Playgroud)

相对的html是:

<Label *ngFor="let story of stories" [text]='story.message'></Label>
Run Code Online (Sandbox Code Playgroud)

当应用程序启动时,我只看到一次推送,但是我创建了一个触发"console.log(JSON.stringify(this.stories))"的按钮;" 在那一刻,当我点击按钮时,ui似乎检测到更改的数组,并出现另一个推送的对象.

编辑:

我在这个帖子中创建了一个更简单的例子:Angular 2:当我在ngOnInit中更改promise.than中的变量时,视图不会刷新

es6-promise nativescript angular2-nativescript angular

13
推荐指数
1
解决办法
8216
查看次数

Angular 2:类型'Route []'的参数不能分配给'Route []'类型的参数.

当我更新到最新版本时nativescript-angular,我收到此错误,我想这个问题与Angular 2我正在使用的版本和模块使用的版本之间的差异有关.是否有人能够告诉我应该使用哪些正确的版本才能使其正常工作?请注意,我打算升级到最后一个版本nativescript-angular是为了使用RouterExtensions.

Argument of type 'Route[]' is not assignable to parameter of type  'Route[]'.
  Type 'Route' is not assignable to type 'Route'.
    Types of property 'pathMatch' are incompatible.
      Type 'string' is not assignable to type '"full" | "prefix"'.
        Type 'string' is not assignable to type '"prefix"'.
const routes: Route[]
Run Code Online (Sandbox Code Playgroud)

这些是我的package.json依赖项:

"dependencies": {
    "@angular/common": "2.0.0-rc.4",
    "@angular/compiler": "2.0.0-rc.4",
    "@angular/core": "2.0.0-rc.4",
    "@angular/forms": "0.3.0",
    "@angular/http": "2.0.0-rc.4",
    "@angular/platform-browser": "2.0.0-rc.4",
    "@angular/platform-browser-dynamic": "2.0.0-rc.4",
    "@angular/platform-server": "2.0.0-rc.4",
    "@angular/router": "^3.0.0-rc.1",
    "@angular/router-deprecated": "2.0.0-rc.2", …
Run Code Online (Sandbox Code Playgroud)

angular

4
推荐指数
1
解决办法
5084
查看次数