我只是选择了Angular 6和CLI并创建了一个项目,如下所示
ng new my-demo
cd my-demo
ng g library foo --prefix=my
Run Code Online (Sandbox Code Playgroud)
不在我的库中我想添加,ngx-bootstrap因为组件需要,DropdownButtonModule所以我的问题是我如何安装库的npm包?
我以前刚刚运行npm install ngx-bootstrap但现在将为应用程序安装软件包,但是,我需要为库安装此软件包.我应该cd到库文件夹并运行npm install还是有另一种方法,这是使用CLI完成的?
我刚刚将angular cli更新到了版本6。当然,我的应用程序坏了,并且一直在尝试查看文档和SO问题,试图找出如何向angular.json添加环境?我希望能够运行与ng serve --env = local等效的功能,然后使其在本地服务器中运行本地构建...我已经参与其中,而我的angular.json文件如下所示...
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"bb-admin": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"prefix": "app",
"schematics": {
"@schematics/angular:component": {
"styleext": "sass"
}
},
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/bb-admin",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.sass"
],
"scripts": []
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all", …Run Code Online (Sandbox Code Playgroud) 我的Angular应用程序无法在低于11的IE中运行,但是以前它甚至无法在IE 11中运行,但是在polyfills.ts中取消对某些导入的注释后,它仍然可以工作,但是在较低版本中仍然存在问题。
这分别是我的polyfills.ts,package.json和浏览器控制台错误
polyfills.ts
/**
* This file includes polyfills needed by Angular and is loaded before the
app.
You can add your own extra polyfills to this file.
This file is divided into 2 sections:
1. Browser polyfills. These are applied before loading ZoneJS and are sorted
by browsers.
2. Application imports. Files imported after ZoneJS that should be loaded
before your main file.
*
* The current setup is for so-called "evergreen" browsers; the last versions
of
browsers …Run Code Online (Sandbox Code Playgroud) 我有一个简单的Angular CLI(6.0.7)应用程序,它在src/assets/文件夹中有一些资产.其中一些在Angular组件的CSS文件中被引用.例:
/* src/app/app.component.css */
.test-div {
background: url(../assets/test.png);
}
Run Code Online (Sandbox Code Playgroud)
当我构建项目时,ng build我最终得到一个像这样的输出结构:
dist/
myapp/
assets/
test.png <-- This one is simply copied from the src/asssets folder
index.html
main.js
test.png <-- This one is created by magic Angular CSS processing
...
Run Code Online (Sandbox Code Playgroud)
此外,CSS被重写为指向test.png根目录中的test.png文件而不是文件assets夹中的文件.
我根本不喜欢这种行为.我知道在生产模式下编译应用程序时会有一些好处,它会为从CSS引用的资产文件添加一些哈希前缀以防止缓存,但我不喜欢文件重复以及CSS中引用的资产与手动引用的资产之间的不一致打字稿.所以我宁愿禁用这种特殊的CSS处理,因此Angular不会解析CSS中的URL并保持URL不变.
那么如何禁用Angular CLI的神奇CSS处理呢?
Angular-CLI文档似乎没有包含对angular.json模式的完整引用,是否有地方可以找到可用选项的更完整列表?
我已经在ng update @angular/cli命令的帮助下更新了我的angular-cli .之后,我遇到了Could not determine single project for 'server' target错误跟踪错误.
Could not determine a single project for the 'serve' target.
Error: Could not determine a single project for the 'serve' target.
at ServeCommand.getProjectNamesByTarget (E:\Angular\Projects\projectName\node_modules\@angular\cli\models\architect-command.js:175:19)
at ServeCommand.<anonymous> (E:\Angular\Projects\projectName\node_modules\@angular\cli\models\architect-command.js:128:51)
at Generator.next (<anonymous>)
at E:\Angular\Projects\projectName\node_modules\@angular\cli\models\architect-command.js:7:71
at new Promise (<anonymous>)
at __awaiter (E:\Angular\Projects\projectName\node_modules\@angular\cli\models\architect-command.js:3:12)
at ServeCommand.runArchitectTarget (E:\Angular\Projects\projectName\node_modules\@angular\cli\models\architect-command.js:121:16)
at ServeCommand.<anonymous> (E:\Angular\Projects\projectName\node_modules\@angular\cli\commands\serve.js:34:25)
at Generator.next (<anonymous>)
at E:\Angular\Projects\projectName\node_modules\@angular\cli\commands\serve.js:7:71
Run Code Online (Sandbox Code Playgroud)
这种行为让我很困惑.有关更多信息,我也在package.json这里添加.
{
"name": "ProjectName",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": …Run Code Online (Sandbox Code Playgroud) 我正在使用角度 CLI。
如何删除令牌参数名称和值?
let params = new HttpParams();
params = params.append('siteId', 1);
params = params.append('orgId', 2);
params = params.append('token', 3);
Run Code Online (Sandbox Code Playgroud)
到目前为止,这是我的代码:
validate(email) {
let params = new HttpParams();
params = params.set('email', email);
params = params.set('siteId', this._global.SITEID);
params = params.set('orgId', this._global.ORGID);
params = params.set('domainName', this._global.DOMAIN_NAME);
params = params.set('token', this._global.getRandomUuid());
params.delete('domainName',this._global.DOMAIN_NAME);
return this.api.call('member/duplicate', params);
}
call(url, params) {
// here I want to delete the token param name and value.
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个自定义Webpack模块,以用cli 6覆盖或扩展角度为6的当前SCSS构建,目的是能够传递“品牌”并将其与任何替代匹配,例如“ somemodule /'brand' /filename.override.scss”并替换父文件夹“ somemodule / filename.scss”中的文件,但我没有任何进展。
设置:@ angular / cli“:” 6.2.2“,带有@ angular-builders / custom-webpack”:“ ^ 2.4.1”
我已经更新了项目构建,以反映出我正在使用自定义Webpack,以及覆盖/扩展的位置
"build": {
"builder": "@angular-builders/custom-webpack:browser",
"options": {
"customWebpackConfig": {
"path": "./extra-webpack.config.js"
},
Run Code Online (Sandbox Code Playgroud)
我的extra-webpack.config.js看起来像这样,只是我在许多网站上看到的一种基本的hello世界风格
module.exports = {
module:{
rules: [{
test: /\.scss$/,
use: [{
loader: "style-loader"
}, {
loader: "css-loader"
}, {
loader: "sass-loader",
options: {
includePaths: ["src"]
}
}]
}]
}
};
Run Code Online (Sandbox Code Playgroud)
但是用这个来运行我的构建
ng run websitename:build
Run Code Online (Sandbox Code Playgroud)
引发此错误
Module build failed (from ./node_modules/sass-
Run Code Online (Sandbox Code Playgroud)
loader / lib / loader.js):
^
Invalid CSS after "": …Run Code Online (Sandbox Code Playgroud) 当我跑步时
ng test --watch=false --code-coverage --no-progress
Run Code Online (Sandbox Code Playgroud)
我明白了
Schema validation failed with the following errors:
Data path ".watch" should be boolean.
Run Code Online (Sandbox Code Playgroud)
我进行了搜索,但找不到此错误的命中结果。
文档(https://github.com/angular/angular-cli/wiki/test)明确表示 --watch=false 应该有效。
其他人说它有效,例如https://github.com/angular/angular-cli/issues/10711#issuecomment-387704999
我使用的是 Angular/cli 6.2.4。角度 6.1.9
有人遇到过这种情况吗?
我有两个任务,需要相互运行:
ng build <library-name> && ng serve
Run Code Online (Sandbox Code Playgroud)
我想在 上监视文件更改<libary-name>,因此我添加了以下内容:
ng build <library-name> --watch && ng serve
Run Code Online (Sandbox Code Playgroud)
这显然不起作用,因为手表永远不会完成,所以 ng serve 永远不会被调用。
ng build <library-name> --watch & ng serve
Run Code Online (Sandbox Code Playgroud)
这个解决方案也不好,因为 ng serve 在 ng build 完成之前就开始了。
有什么办法可以从第一个 ng 构建中捕获Compilation complete消息,然后让文件观察器运行?有什么办法可以像这样启动观察者:
ng build <library-name> && --watch-the-libary-please & ng serve
Run Code Online (Sandbox Code Playgroud)
?
angular-cli-v6 ×10
angular ×8
angular-cli ×5
angular6 ×2
angular5 ×1
npm ×1
sass ×1
webpack ×1