templateUrl 对我不起作用 [英] templateUrl does not work for me

查看:29
本文介绍了templateUrl 对我不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照 angular.io 入门项目使用种子结构.到目前为止一切正常.

I use the seed structure as per angular.io get started project. Everything OK so far.

现在我想将顶部组件更改为从单独的文件中查看视图,但我遇到了麻烦.工作代码是:

Now I wanted to change the top component to have a view from a separated file and I get into troubles. The working code is:

import {Component, View} from 'angular2/core';
@Component({
       selector: 'my-app',
       template: '<h1>Angular2</h1>',
       directives: []
})
export class AppComponent {
       constructor() {  
       }
}

然后我将模板更改为 templateUrl,如下所示:

Then I change the template to templateUrl like so:

templateUrl: 'app.component.html',

我在此文件中的代码与以前完全相同

where I have in this file the exact same code as before

Angular2

似乎很明显可以工作,但事实并非如此.它不会吐出错误,但除了入门演示中的正在加载...."消息外,它不会显示任何内容

Seems to be obvious to work but it does not. It does not spit errors but it does not display anything except the 'loading....' message as in the get started demo

感谢您的帮助

彼得

推荐答案

在@Component 装饰器中添加 moduleId: module.id.如果您没有,那么 Angular 2 将在根级别查找您的文件.

Add moduleId: module.id in the @Component decorator. If you don't have that then Angular 2 will be looking for your files at the root level.

import {Component} from 'angular2/core';

@Component({
  selector: 'my-app',
  moduleId: module.id,
  templateUrl: 'app.component.html'
})

export class AppComponent { }  

查看这篇文章

这篇关于templateUrl 对我不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆