安装角之后,打字稿编译器不断收到一些错误约没有找到Promise,Map,Set和Iterator.
到现在为止我忽略了它们,但现在我需要Promise这样我的代码可以工作.
import {Component} from 'angular2/core';
@Component({
selector: 'greeting-cmp',
template: `<div>{{ asyncGreeting | async}}</div>`
})
export class GreetingCmp {
asyncGreeting: Promise<string> = new Promise(resolve => {
// after 1 second, the promise will resolve
window.setTimeout(() => resolve('hello'), 1000);
});
}
Additional information:
npm -v is 2.14.12
node -v is v4.3.1
typescript v is 1.6
Run Code Online (Sandbox Code Playgroud)
错误:
................ERROS OF MY CODE.................
C:\Users\armyTik\Desktop\angular2\greeting_cmp.ts
Error:(7, 20) TS2304: Cannot find name 'Promise'.
Error:(7, 42) TS2304: …Run Code Online (Sandbox Code Playgroud) 我正在使用Angular 2框架构建一个Web应用程序,我想使用外部模板(https://freehtml5.co/preview/?item=splash-free-html5-bootstrap-template-for-any-websites).
我需要在我的组件模板中运行一些脚本(jquery.min.js,bootstrap.js,...),但是如果我把它放到脚本标签中则不起作用.
如果我在index.html中运行脚本标记它可以工作,但是当我浏览到另一个页面脚本时,不会重新加载.
如何在模板中加载没有脚本标记的脚本?
的index.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Angular2App</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<!-- Facebook and Twitter integration -->
<meta property="og:title" content="" />
<meta property="og:image" content="" />
<meta property="og:url" content="" />
<meta property="og:site_name" content="" />
<meta property="og:description" content="" />
<meta name="twitter:title" content="" />
<meta name="twitter:image" content="" />
<meta name="twitter:url" content="" />
<meta name="twitter:card" content="" />
<!--<link href="build/main.css" rel="stylesheet">-->
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,700" rel="stylesheet">
<!-- Animate.css -->
<link rel="stylesheet" href="assets/css/animate.css">
<!-- …Run Code Online (Sandbox Code Playgroud) 我正在使用angular 5应用程序(Angular CLI:1.6.1)添加jsplumb社区js库版本.
使用没有任何配置tsconfig.json的第一个生成我得到以下错误.
ERROR in src/app/jsplumb/jsplumb.component.ts(4,25): error TS6143: Module '../../../node_modules/jsplumb/dist/js/jsplumb.js' was resolved to 'D:/myproj/angular5/myapp/node_modules/jsplumb/dist/js/jsplumb.js', but '--allowJs' is not set.
Run Code Online (Sandbox Code Playgroud)
使用"allowJs":tsconfig.json中的true会出现以下错误
ERROR in error TS5055: Cannot write file 'D:/myproj/angular5/myapp/node_modules/jsplumb/dist/js/jsplumb.js' because it would overwrite input file.
Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig.
Run Code Online (Sandbox Code Playgroud)
根据tsconfig FAQ
为什么我收到错误TS5055:无法写入文件'xxx.js',因为它会覆盖输入文件.
使用outDir("outDir":"./ dist/out-tsc")此问题应该得到解决.这已在我的tsconfig中设置.
如果我们将noEmit添加到true它只是构建应用程序,不包括任何js我们得到一个空白的白色屏幕.
让我知道是否有人试图用新的角度cli包含外部js并面临同样的错误,同样的解决方案是什么.
没有任何附加选项添加到tsconfig.json,如果我尝试修改任何ts文件,应用程序将成功编译,我能够工作.但是,在运行ng build时,这无助于创建可部署的二进制文件.
更新解决方法:直到CLI中的修复程序可用.对于开发(ng serve),从tsconfig.json中删除allowJs,当你因添加allowJs而出错时只需修改一个ts文件来重新编译应用程序,这次将成功编译.对于生产或分发,将allowJs添加回tsconfig.json运行应用程序运行,ng build --prod --watch=auto你应该看到有关覆盖node_module中的JS文件的错误,简单修改它应该重建的ts文件,因为--watch = auto在命令中但是这个成功的时间.
我在AngularJS项目中使用基于jQuery的select2组件.我和这里的人有类似的问题:https://github.com/fronteed/icheck/issues/322,并使用那里的建议解决了它.准确地说,我TypeError: $(...).select2 is not a function在没有使用该建议时收到错误.
即我在Webpack的配置中添加了下一行@angular/cli/models/webpack-configs/common.js.
plugins: [
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery"
})
]
Run Code Online (Sandbox Code Playgroud)
它是在angular/cli中启用jQuery的最佳方法吗?
我不认为在https://github.com/angular/angular-cli/wiki/stories-global-lib中做同样的事情是正确的,因为
a)webpack捆绑jQuery而无需在脚本中指定它
b)TypeError: $(...).select2 is not a function当你按照故事中所描述的那样包含它时,它仍会抛出错误.
在我的angular cli项目中,我需要引用不是节点包的外部js库.因此,它们不会位于node_modules文件夹下,因为它们不是由npm安装的.这些是松散的js文件.
下面的链接解释了我们如何在.angular-cli.json文件的脚本数组中引用它们.但是,如果它们不是节点模块,它不会告诉外部js文件应该在angular cli项目的文件夹结构中添加到何处. Angular Cli Webpack,如何添加或捆绑外部js文件?