加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

typescript – Angularjs 2.0不加载templateUrl

发布时间:2020-12-17 17:21:27 所属栏目:安全 来源:网络整理
导读:我是 Angularjs-2.0的新手.我创建了一个示例应用程序,在加载templateUrl时遇到了问题. 我的app.ts文件: import {bootstrap,Component} from 'angular2/angular2';@Component({ selector: 'my-app',templateUrl: 'grid.html'})class AppComponent { }bootstr
我是 Angularjs-2.0的新手.我创建了一个示例应用程序,在加载templateUrl时遇到了问题.

我的app.ts文件:

import {bootstrap,Component} from 'angular2/angular2';
@Component({
    selector: 'my-app',templateUrl: 'grid.html'
})
class AppComponent { }
bootstrap(AppComponent);

我改变了./grid.html之类的路径,但它对我也不起作用.

谁来帮帮我..!

解决方法

如果你的目录结构是这样的:

|- app
   |- grid.html
   |- component.ts
   myApp.ts

然后使用templateUrl:’app / grid.html’.

更新

上面的解决方案使我们硬编码应用程序/在每个地方包含这些文件.所以这是另一个:

>在文件tsconfig.json中定义“module”:“commonjs”
>将新行moduleId:module.id添加到@Component装饰器.

所以它变成:

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

参考:

> Angular cannot find templateUrl
> Angular2 beta relative paths for templateUrl and styleUrls

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读