1.我下完jquery跟bootstrap了,而且在angular-cli里边也添加了,启动的时候报错了。
解决方案:下载一个npm install bootstrap@4.0.0-alpha.6。项目就可以正常启动了 ,或者说是下一个低版本的bootstrap,我后来又下了一个3.3.7的版本试了一下,也是好使的,就连之前有些样式不出来,现在也是出来了。
2.我启动angular的时候走的是index.html页面,但是我的内容写在了src下面的app.component.html里边,我现在想显示app.component.html这个页面里边的内容,要怎么做呢?
问题回答:我要在首页的body里边配置<app-root></app-root>,这个是在app.component.ts里边进行配置的。
--save是把当前这个一来记到package.json里边
使用第三方类库做3件事情:
- 将第三方类库安装到本地(使用npm install安装)
- 把库引入到项目中去,找到angular-cli文件里边的apps下面的styles数组跟javascript数组。Jquery可能会出一个错误,因为jquery是javascript的东西,typescript是不能够直接用的,需要把jquery和bootstrap的typescript的类型描述文件安装到库里边。才认识jquery的东西。(npm install @types/jquery –save-dev,npm install @types/bootstrap –save-dev)
- 在安装npm i的时候报错?npm ERR! Unexpected end of JSON input while parsing near '...s-reporter":"latest",'
解决方案:1.执行npm cache clean –force指令。2.执行npm cache verify。3.我的是因为我之前安装了淘宝镜像,所以导致冲突,我把npm都删掉了,重新下的脚手架。
可能是有大量的缓存需要清除,具体可查看npm缓存目录。
4.当安装完之后会出现这个错误
解决方案:需要下载一下那个模块:npm install @angular-devkit/core
5.代码写完了,但是页面是空白的。
我把forroot换成了forchild就好使了,但是这种方法并不对,但是在不知道什么错误的时候,还没有任何报错的情况下只能是一点一点的试了。后来我又重新试了一下,既然不显示那应该什么没写对或者是少什么,果然在我写的时候我把首页的东西都删除掉了,
<base href="/">
少了一行这个标签,一失足成千古恨哈,很小的问题花了我很长的时候来找错。
6.管道模块报错
最后发现原始是import那的单引号写错了,写到了下面。
8.接着又报了一个这个错误:
compiler.js:486 Uncaught Error: Template parse errors:
No provider for ControlContainer ("[ERROR ->]<form name="searchForm" role="form">
<div class="form-group">
<label for="productTitle">商品名称:</"): ng:///AppModule/SearchComponent.html@0:0
at syntaxError (compiler.js:486)
at TemplateParser.parse (compiler.js:24674)
at JitCompiler._parseTemplate (compiler.js:34629)
at JitCompiler._compileTemplate (compiler.js:34604)
at eval (compiler.js:34505)
at Set.forEach (<anonymous>)
at JitCompiler._compileComponents (compiler.js:34505)
at eval (compiler.js:34375)
at Object.then (compiler.js:475)
at JitCompiler._compileModuleAndComponents (compiler.js:34374)
解决方案:跟formControl有关系,具体原因也没检查出来()
9.在写表单的时候报错
解决方案:在app.module.ts文件里边没有引入表单模块
import {FormsModule} from '@angular/forms'
- 当你写完代码去浏览器访问,但是发现浏览器的页面是空白的?
解决方案:这个时候你要去查看一下刚才写的代码是不是有变量没有写明是什么类型。
- 写完代码在首页报错:
Uncaught Error: Template parse errors:
There is no directive with "exportAs" set to "ngModel" ("gSubmit)="onsubmit(myForm.value)">
解决方案:这个是你的模板写的不对,你设置的ngModel有问题,我是在密码那把ngModel加上了。