首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Angular2渲染应用程序2次

Angular2渲染应用程序2次
EN

Stack Overflow用户
提问于 2016-08-29 19:17:43
回答 1查看 124关注 0票数 0

我有一个问题,我不能进入路由在角度2。Mb有人fased与类似的东西?

所以,我的应用程序以一种奇怪的方式呈现:

代码语言:javascript
复制
<my-app><div> <app-nav-bar _nghost-ile-2=""><ul _ngcontent-ile-2=""> <!--template bindings={
  "ng-reflect-ng-for-of": "[object Object],[object Object],[object Object],[object Object]"
}--><li _ngcontent-ile-2="" ng-reflect-raw-style="[object Object]" style="float: left;"> <a _ngcontent-ile-2="" ng-reflect-raw-class="[object Object]" ng-reflect-href="/" href="/">Home</a> </li><li _ngcontent-ile-2="" ng-reflect-raw-style="[object Object]" style="float: left;"> <a _ngcontent-ile-2="" ng-reflect-raw-class="[object Object]" ng-reflect-href="/index/books" href="/index/books">Books</a> </li><li _ngcontent-ile-2="" ng-reflect-raw-style="[object Object]" style="float: right;"> <a _ngcontent-ile-2="" ng-reflect-raw-class="[object Object]" class="active" ng-reflect-href="/index/about" href="/index/about">About</a> </li><li _ngcontent-ile-2="" ng-reflect-raw-style="[object Object]" style="float: right;"> <a _ngcontent-ile-2="" ng-reflect-raw-class="[object Object]" ng-reflect-href="/" href="/">Login</a> </li> </ul> </app-nav-bar> <router-outlet></router-outlet><app-hello _nghost-ile-4="">
<html _ngcontent-ile-4="">
<head _ngcontent-ile-4="">
  <link _ngcontent-ile-4="" class="__meteor-css__" href="/merged-stylesheets.css?hash=d42394b95cde74014bba42c21ff2737c29b8fc61" rel="stylesheet" type="text/css">
    <base _ngcontent-ile-4="" href="/">
</head>
<body _ngcontent-ile-4="">
  <my-app _ngcontent-ile-4="">Loading....</my-app>
</body>
</html>
</app-hello> </div> </my-app>

如您所见,my-app>(app-nav-bar+app-hello)>html>(head+body)等。

文件main.ts:

代码语言:javascript
复制
import { bootstrap } from 'angular2-meteor-auto-bootstrap';
import { disableDeprecatedForms, provideForms } from '@angular/forms';
import {APP_ROUTER_PROVIDERS} from './app.routes'

import { AppComponent } from './app.component';

bootstrap(AppComponent, [
    disableDeprecatedForms(),
    provideForms(),
    APP_ROUTER_PROVIDERS
]);

文件app.routes.ts

代码语言:javascript
复制
import {

RouterConfig, provideRouter } from '@angular/router';

import {
    HelloComponent
} from './imports/index'

const routes: RouterConfig = [
    { path: '', component: HelloComponent }
];

export const APP_ROUTER_PROVIDERS = [
    provideRouter(routes)
];

文件app.component.html:

代码语言:javascript
复制
<div>
    <app-nav-bar></app-nav-bar>
    <router-outlet></router-outlet>
</div>

文件index.html:

代码语言:javascript
复制
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <base href="/">
    <meta viewport>
</head>
<body>
<my-app>Loading....</my-app>
</body>

如果有人能帮助我,我会很高兴。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-10-08 18:10:47

我不确定这是否是正确的答案,但看起来我错过了包,它允许我直接使用静态模板。所以,替换掉

代码语言:javascript
复制
import template from 'ex.controller.html'

@Component({
...
template,
...
})

有了这个

代码语言:javascript
复制
@Component({
...
template: 'ex.controller.html',
...
})

和删除导入帮助了很大的一部分。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39204968

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档