使用npm,我按照Angular CLI快速入门页面上的入门指示进行操作.
ng serve --open在创建并进入我的新项目"frontend"后运行会出现此错误:
Could not find module "@angular-devkit/build-angular" from "C:\\Users\\Brandon\\project-name\\frontend".
Error: Could not find module "@angular-devkit/build-angular" from "C:\\Users\\Brandon\\project-name\\frontend".
at Object.resolve (C:\Users\Brandon\project-name\node_modules\@angular-devkit\core\node\resolve.js:141:11)
at Observable.rxjs_1.Observable [as _subscribe] (C:\Users\Brandon\project-name\node_modules\@angular-devkit\architect\src\architect.js:132:40)
Run Code Online (Sandbox Code Playgroud)
我尝试过与我类似的其他问题的建议,但是没有用.回答是跑npm install --save-dev @angular-devkit/build-angular.
我还删除了模块,清除了缓存,然后做了一个也没有用的安装.
的package.json:
{
"name": "frontend",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^6.0.2",
"@angular/common": "^6.0.2",
"@angular/compiler": "^6.0.2",
"@angular/core": "^6.0.2",
"@angular/forms": "^6.0.2",
"@angular/http": …Run Code Online (Sandbox Code Playgroud) 在安装NPM 6之后,几乎我在Angular 6项目上安装的每个NPM软件包都存在漏洞.
我应该每次"npm审核修复"每个包吗?我应该重新安装NPM 5吗?其他方案?
这是我使用的终端sequlize代码及其漏洞:
npm i sequelize --save
npm WARN @angular/material@6.2.1 requires a peer of @angular/cdk@6.2.1
but none is installed. You must install peer dependencies yourself.
+ sequelize@4.37.10
added 16 packages from 39 contributors and audited 22308 packages in
10.659s
found 9 vulnerabilities (3 low, 5 moderate, 1 high)
run `npm audit fix` to fix them, or `npm audit` for details
Run Code Online (Sandbox Code Playgroud) 正如标题所示,我使用了生成基础库ng generate library lib; 然后我生成了另一个名为的库lib2.我希望使用一些基本组件或服务lib,所以我lib在lib2模块中导入,但npm run build lib2失败了.
我收到了这个错误:error TS2307: Cannot find module 'lib'.
如何正确导入基础库?任何帮助表示赞赏.
我正在使用角度最新版本的工作空间概念(> 6).
CLI可以生成一个项目,该项目是一个带有如下命令的库:
ng generate library api
Run Code Online (Sandbox Code Playgroud)
默认应用程序的tsconfig.json是这样的
"paths": {
"env": ["src/environments"],
"api": [
"dist/api"
],
Run Code Online (Sandbox Code Playgroud)
之后我在api库中创建了一个名为ApiService的服务,但是它没有用
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { environment } from 'env';
@Injectable()
export class ApiService {
constructor(private http: HttpClient) {}
getApiUrl(){
console.log("Hello Api Url"+environment.api_url)
}
}
Run Code Online (Sandbox Code Playgroud)
使用命令构建api库时返回错误ng build api:
BUILD ERROR
error TS6059: File 'ROOT_APP_PATH/src/environments/environment.ts'
is not under 'rootDir' 'ROOT_APP_PATH\projects\api\src'.
'rootDir' is expected to contain all source files.
Run Code Online (Sandbox Code Playgroud)
请帮助解决此错误.
提前致谢.
我有一个角度的提要服务,它调用一个REST端点,该端点返回EntryDTO列表。服务外观如下:
@Injectable({providedIn: 'root'})
constructor(private http: HttpClient) {}
export class FeedService() {
getPublicFeedEntries: Observable<EntryDTO[]> () {
return this.http.get('/rest/publicFeedEntries/).map((response: Response) => response.json()).catch((err: any) => Observable.throw(error.josn().error || 'error');
}
}
Run Code Online (Sandbox Code Playgroud)
因此,我可以拥有一个订阅此可观察值的提要组件:
export class FeedComponent() {
private feedEntries: EntryDTO[];
constructor(private feedService: FeedService) { feedEntries = new Array(); }
ngOnInit() {
this.feedService.getPublicFeedEntries.subscribe(entries => {
this.feedEntries = entries;
}, err => {console.log(err) })
}
}
Run Code Online (Sandbox Code Playgroud)
这是否被视为在服务中返回可观察对象并订阅组件的最佳实践,还是还有其他最佳实践?
<mat-sidenav-container class="sidenav-container">
<mat-sidenav #drawer class="sidenav" fixedInViewport="true" [attr.role]="(isHandset$ | async) ? 'dialog' : 'navigation'"
[mode]="(isHandset$ | async) ? 'push' : 'push'" [opened]="!(isHandset$ | async)">
<mat-toolbar color="primary">Menu</mat-toolbar>
<mat-nav-list>
<a mat-list-item href="#">Link 1</a>
<a mat-list-item href="#">Link 2</a>
<a mat-list-item href="#">Link 3</a>
</mat-nav-list>
</mat-sidenav>
Run Code Online (Sandbox Code Playgroud)
我不明白代码中写的是什么,(isHandset$ | async)请解释一下
我使用角度6,我跟随这个视频教程提交图像.
我想观察表单提交的进度,这样我就可以得到上传文件的百分比.
我的组件中有这个
import { HttpClient,HttpEventType } from '@angular/common/http';
import { Http, Headers } from '@angular/http';
constructor(
private formBuilder: FormBuilder,
private myService:MyService,
private changeDetector: ChangeDetectorRef,
private carouselConfig : NgbCarouselConfig ,
private http:HttpClient
) { }
let headers = new Headers();
headers.append('Authorization',this.token);
let eb =null;
this.http.post('http://localhost:3000/cms/upload',formData,{reportProgress:true,observe:'events'}).subscribe(
event=>{
if(event.type === HttpEventType.UploadProgress){
let pv = Math.round(event.loaded / event.total *100);
this.imguploadprogress.nativeElement.value = pv;
}
else if(event.type === HttpEventType.Response){
eb = event.body;
if(eb.success){
this.imguploadprogress.nativeElement.value = 100;
this.imageMsg='All good';
}
else{
this.imguploadprogress.nativeElement.value = 0; …Run Code Online (Sandbox Code Playgroud) 我们正在使用 Angular 的内置工具从模板中提取消息。
这工作正常,我们使用以下命令获取 XLIFF 文件中的所有信息:
ng xi18n
Run Code Online (Sandbox Code Playgroud)
在这个文件中,atrans-unit看起来像这样:
<trans-unit id="3535a6c8296b457542000d2cbd15ca93f86cdd79" datatype="html">
<source>Homepage</source>
<context-group purpose="location">
<context context-type="sourcefile">app/component/nav/nav.component.html</context>
<context context-type="linenumber">39</context>
</context-group>
<note priority="1" from="description">description</note>
<note priority="1" from="meaning">title</note>
</trans-unit>
Run Code Online (Sandbox Code Playgroud)
尽管其中的内容<context-group purpose="location">看起来很有趣,但它向外部翻译服务解释了项目和实施细节。
有没有办法告诉 Angular 不要将这些信息包含到 XLIFF 文件中?
或者,是否有其他工具可以进行转换?也许编译器在构建过程中获得这些信息很重要。
我试图在 window.print 打开后,当用户单击“取消”时进行重定向。
这将打开窗口打印
printHc(){
window.print();
}
Run Code Online (Sandbox Code Playgroud)
现在,如果用户取消打印,我想重定向到另一条路线。例如
this.router.navigate("other_page");
Run Code Online (Sandbox Code Playgroud)
我如何在 Angular 6 中的 typescript 上监听此事件(使用 chrome)?
我从后端获取了超过 30000 条记录并在前端列出,因此使用 cdk-virtual-scroll 我可以实现这一目标。我创建了用 cdk-tag 括起来的普通表
<cdk-virtual-scroll-viewport [itemSize] = "20">
<div class="result_table">
<table class="dataframe" border="1">
<thead>
<tr>
<th >
Name
</th>
<th >
Description
</th>
<th >
Group
</th>
<th >
Data
</th>
</tr>
</thead>
<tbody>
<tr *cdkVirtualFor ="let data of address_obj_data_holder | filter:searchAddr">
<td >
{{data.name}}
</td>
<td >
{{data.description}}
</td>
<td >
{{data.group}}
</td>
<td >
{{data.data}}
</td>
</tr>
</tbody>
</table>
</div>
</cdk-virtual-scroll-viewport>
Run Code Online (Sandbox Code Playgroud)
如果我这样做,当我向下滚动时,表格标题也会滚动,如果我喜欢,
<cdk-virtual-scroll-viewport [itemSize] = "20">
<div class="result_table">
<table class="dataframe" border="1">
<thead>
<tr>
<th style="width: …Run Code Online (Sandbox Code Playgroud) angular6 ×10
angular ×7
angular-cli ×2
npm-install ×2
angular8 ×1
audit ×1
css ×1
html ×1
mat-sidenav ×1
node.js ×1
npm ×1
package.json ×1
security ×1
sidenav ×1
typescript ×1
xliff ×1