Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.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
Typescript 角度2路由器组件在交互之前不初始化_Typescript_Angular_Angular2 Routing - Fatal编程技术网

Typescript 角度2路由器组件在交互之前不初始化

Typescript 角度2路由器组件在交互之前不初始化,typescript,angular,angular2-routing,Typescript,Angular,Angular2 Routing,加载路由时,将呈现其模板的所有静态内容。但是,在进行第一次交互之前,所有具有绑定的元素都是隐藏的 将项目简化为最简单的项目后,我有以下几点: 应用程序组件.ts import { Component } from '@angular/core'; import { RouteConfig, ROUTER_DIRECTIVES } from '@angular/router-deprecated'; import { DashboardComponent } from './dashboard/

加载路由时,将呈现其模板的所有静态内容。但是,在进行第一次交互之前,所有具有绑定的元素都是隐藏的

将项目简化为最简单的项目后,我有以下几点:

应用程序组件.ts

import { Component } from '@angular/core';
import { RouteConfig, ROUTER_DIRECTIVES } from '@angular/router-deprecated';

import { DashboardComponent } from './dashboard/';
import { PagesComponent } from './pages/';

@Component({
    selector: 'admin-app',
    templateUrl: 'admin.component.html',
    directives: [ROUTER_DIRECTIVES]
})
@RouteConfig([
    { path: '/', name: 'Dashboard', component: DashboardComponent },
    { path: '/pages', name: 'Pages', component: PagesComponent },
])
export class AdminAppComponent {
    test = 'Binding from main component';
    constructor() {
    }
}
import { Component } from '@angular/core';

@Component({
    moduleId: module.id,
    selector: 'go-pages',
    templateUrl: 'pages.component.html',
    styleUrls: ['pages.component.css']
})
export class PagesComponent {
    test = 'YES';
    constructor() { }
}
app.component.html


{{test}}

在浏览器中,会发生以下情况:

  • {{test}

    始终呈现为“从主组件绑定”
  • 页面工作正常

    也总是渲染
  • 绑定工作->{{test}

    有时在开始时呈现,但大多数时候我必须再次单击
    页面
    ,然后它总是出现

我使用的是angular和router不推荐的2.0.0-rc.1。

如何提供
路由器提供程序
?在bootstrap:
引导(AdminAppComponent,[router\u PROVIDERS])
你能在Chrome或其他浏览器中复制吗?这发生在Chrome、Firefox和IE上一版本的所有浏览器上不知道。我第一次看到这个问题。我建议使用新的路由器,而不是在不推荐使用的路由器上浪费更多的时间。