尝试要求一个html文件时,我有一个奇怪的错误.有问题的代码是一个用typescript编写并使用webpack的AngularJs应用程序.
app.directive.ts
// require('./app.scss');
// import AppController from './app.controller';
function AppDirective(): ng.IDirective {
return {
restrict: 'E',
scope: {},
controllerAs: 'vm',
// controller: AppController,
controller: () => {},
// template: require('./app.html')
template: '<div>this is a test</div>'
}
}
angular
.module('myApp')
.directive('appDirective', AppDirective);
Run Code Online (Sandbox Code Playgroud)
app.controller.ts
export default class AppController {
public static $inject = ['$scope'];
constructor(private $scope) {
}
}
Run Code Online (Sandbox Code Playgroud)
app.html
<div>
THIS IS A TEST, REMAIN CALM
</div>
Run Code Online (Sandbox Code Playgroud)
app.scss是空的.
现在,实际上,包含注释,此代码在webpack中构建时没有错误,并将使用webpack dev服务器进行部署.
使用webpack dev服务器,它允许您在服务器运行时更改代码并重新加载它,我可以取消注释任何/所有注释行,它将正常工作.
但是,如果我关闭开发服务器并重建,它将无法给出此错误:
未捕获的TypeError:无法读取未定义的属性"call"
Uncaught TypeError: Cannot read property 'call' …Run Code Online (Sandbox Code Playgroud)