【发布时间】:2017-09-27 18:25:33
【问题描述】:
我尝试使用指令 ([]) 声明我的组件,但没有成功。然后我知道在 RC6 中它已被弃用。所以我在声明@ngmodule 中添加了组件,但它仍然不知道为什么?
编辑 ::
那是我的 module.ts ::
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import {NavBarComponent} from "./Components/navbar/navbar.component";
import {AboutComponent} from "./Components/about/about.component";
@NgModule({
imports: [ BrowserModule ],
declarations: [ AppComponent ,NavBarComponent , AboutComponent],
bootstrap: [ AppComponent ]
})
export class AppModule { }
那是我的 app.component.ts ::
import { Component } from '@angular/core';
//import {AboutComponent} from "./Components/about/about.component";
@Component({
selector: 'my-app',
template: `<h1>{{name}}</h1>`,
})
export class AppComponent { }
现在 NavBar 组件有 .html 文件 ::
<nav class="navbar navbar-inverse ">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Spotify</a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#about">About</a></li>
</ul>
</div>
</div>
</nav>
还有 Navbar.component.ts ::
import {Component} from "@angular/core";
@Component({
moduleId: module.id,
selector: 'navbar',
templateUrl : 'navbar.component.html',
})
export class NavBarComponent { }
我正在使用角度快速启动,没有输出错误,但是当我重新加载页面时没有发生任何变化并且导航栏设计不显示
【问题讨论】:
-
你使用哪个 Angular 版本?
-
我正在使用 angular/cli 版本 1.0.1 @DmitrijKuba
-
您能否提供一个minimal reproducible example 来解释“它没有成功” 的含义?
-
@jonrsharpe 我编辑了它,抱歉不清楚
标签: angular angular2-directives