[英]AngularJS gives an error (ngRoute, DevExtreme, TypeScript)
[英]Using 'import * as' in a typescript component gives an error -
我正在尝试将html模板导入到打字稿组件中 ,这给了我一个错误。 我正在使用Angular 1.5。
该组件看起来像这样...
import * as template from './home.template.html';
import { HomeController } from './home.controller';
export const HomeComponent = {
bindings: {
conf: '<',
},
controller: HomeController,
template,
};
多数民众赞成在这样添加到模块...
import * as angular from 'angular';
import { HomeComponent } from './home.component';
export const HomeModule = angular.module('home', [])
.component('home', HomeComponent);
我得到的错误是...
类型'{的参数绑定:{conf:string;}; 控制器:typeof HomeCon ...'不可分配给'IComponentOptions'类型的参数。 属性'template'的类型不兼容。类型'typeof'.html' 不能分配给'string | ((... args:any [])=>字符串)| (string |(((... args:any [])=> string))[]'。 类型'typeof'.html'不能分配给类型'(string |((... args:any [])=> string))[]'。 类型'typeof'* .html'中缺少属性'find'。
如果我将template: template.toString()
添加到HomeComponent,它似乎可以工作。 但这对我来说并不对。 还有其他建议吗?
在类型声明中的某处,您需要声明一个以.html结尾的模块
declare module '*.html' {
const template: string;
export default template;
}
有了这个声明,您的代码应无需其他更改即可运行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.