新添加的角度2组件不起作用;它已正确添加到app.module.js

时间:2017-01-24 08:12:49

标签: angular

我使用ng new hellong build创建了一个新的角度2项目。然后使用ng serve,我查看它效果很好,显示应用有效!'。

接下来,我添加了一个包含ng g component hello的新组件。下一个是app.module.ts,会自动修改。

...
import { AppComponent } from './app.component';
import { HelloComponent } from './hello/hello.component';//<--here

@NgModule({
  declarations: [
    AppComponent,
   HelloComponent//<--here
  ],
...

hello.component.ts的组成部分是这样的。 hello.component.html有一个默认的html源代码。

@Component({
  selector: 'hello',
  templateUrl: './hello.component.html',
  styleUrls: ['./hello.component.css']
})

然后我最终在<hello>Loading!!!</hello>中添加index.html并再次使用ng serve运行项目,但<hello>标记仅显示&#34;正在加载!!!&#34;

我有什么遗失的吗?

1 个答案:

答案 0 :(得分:3)

请勿在{{1​​}}中添加<hello>标记,将其添加到index.html您的hello组件为app.component.html

或者您可以使用

child/directive
相关问题