angular2使用中问题解决集(不断更新)

来源:互联网 发布:淘宝卖的黄金是真的吗 编辑:程序博客网 时间:2024/05/18 21:10
1 Cannot bind to 'ngModel' 

在app.module.ts中import这个formsModule。 

import{ FormsModule}from'@angular/forms'; //在顶部引入

imports: [FormsModule] //在这里要导入


2 什么时候需要写$scope.apply() 


在angularjs无法使用原生和自己定义的事件(前面不加ng),要用类似ng-click,否则无法进行脏检查,如果click,那么手动去触发$scope.apply() 



3 tslint.json 检验检查 

Angular2中使用的Typescript书写规范比较多,如果想关闭某些检查,可在项目tslint.json中修改某些校验设置


quotemark:true //设成false可关闭单双引号的检查

triple-equals:true //设成false可关闭必须"==="(三等号)的写法
no-trailing-whitespace:false //允许代码后面有空格,包括换行

no-var-keyword":true //不能使用var,针对es6

no-inferrable-types:true //类型推断检查


4 typescript错误信息列表

https://www.tslang.cn/docs/handbook/error.html


原创粉丝点击