angular-cli使用es6模块作为TypeScript的输出格式:在tsconfig.json中:
{
"compilerOptions": {
"modules": "es6",
"target": "es5",
...
Run Code Online (Sandbox Code Playgroud)
以后如何通过webpack处理它以使其在es5中运行?
如果我理解正确,许多项目使用babel来使es6模块工作,但我没有在angular-cli中找到任何关于babel的引用.
我试图从一开始就设置一个webpack项目,因为事实证明angular-cli使用的webpack配置对我们的项目来说不够好/不够灵活.
当我尝试使用es6模块时,我最终在我的"捆绑"js文件中使用了未经处理的"import"语句,所以很明显我做错了.
在这段代码中,我想从cart_products数组中删除一个元素.
var cart_products = ["17^1", "19^1", "18^1"];
var product = 17;
$.each(cart_products,function(key, item) {
if(item.indexOf(product+"^") !== -1){
cart_products.splice(key, 1);
}
});
Run Code Online (Sandbox Code Playgroud)
但我在Google Chrome控制台中收到此错误:
未捕获的TypeError:无法读取未定义的属性'indexOf'
代码有问题吗?
谢谢你的帮助.