标签: angular6

在Angular 6中生成没有*.spec.ts的组件

在以前的版本中,可以使用.angular-cli.json禁用spec.ts,如下所示.有什么办法在版本6.0.0中使用angular.json吗?

"defaults": {
    "component": { 
        "spec": false 
    },
    "service": { 
        "spec": false 
    },
    ...
}
Run Code Online (Sandbox Code Playgroud)

angular6

3
推荐指数
3
解决办法
8361
查看次数

Angular 6 - 使用*ngFor显示数据的问题(数据未显示)

我有一些看起来像这样的数据:

在此输入图像描述

在我身上app.component.html我有这个:

<ul>
  <li *ngFor="let data of myData">{{data.id}}</li>
</ul>
Run Code Online (Sandbox Code Playgroud)

当我运行它时它显示列表但没有任何值,所以我只是从中得到了很多点 <li>

在我的app.component.ts身上:

myData;
Run Code Online (Sandbox Code Playgroud)

然后:

this.myData = obj; // Obj contains the data
Run Code Online (Sandbox Code Playgroud)

我怎样才能解决这个问题?

typescript angular angular6

3
推荐指数
1
解决办法
2万
查看次数

错误:尝试在angular 6中创建通用应用程序的构建时,在工作区问题中找不到项目“ testapp”

我试图通过遵循此链接来创建角度为6的通用应用程序。完成链接中提到的步骤后,我尝试构建通用应用程序,但显示以下错误。

Project 'testapp' could not be found in workspace.
Error: Project 'testapp' could not be found in workspace.
Run Code Online (Sandbox Code Playgroud)

谁能帮我解决这个问题?

angular6

3
推荐指数
1
解决办法
5893
查看次数

Rxjs 6:使用catchError()可以为您提供“未定义”的预期流。您可以提供一个Observable,Promise,Array或Iterable

我正在使用新语法来遵守RxJS 6 pipe()。同样使用Angular6。我有一个处理http请求的服务,它通过管道catchError传输地图并在出现连接错误时显示祝酒词。不过,如果我添加,catchError我会进入控制台,您在期望流的位置提供了“ undefined”。您可以提供一个Observable,Promise,Array或Iterable。

  getDataHttpRequest(url, returnType) {
    return this.http.get(url, this.getRequestOptions())
    .pipe(
      map((response) => {

        if(response){

        if (returnType === 'object') {
          return response[0] == undefined ? response : response[0];
        } else {
          return response;
        }

      }
      }),
      catchError((error):any => {

      if(error instanceof HttpErrorResponse && error.status === 0){
        //no connection error(either user has no connection or the server is down)
       this.toastr.error('Chequee su conexión e intente de nuevo en unos momentos. Contáctenos para reportar el problema a …
Run Code Online (Sandbox Code Playgroud)

rxjs angular angular6 rxjs6

3
推荐指数
1
解决办法
4594
查看次数

Angular:如何检查某些控件是否存在于表单中

以下是我的代码,可从服务获得响应。在这里,我得到了员工名单。

我需要根据服务的响应动态地绑定表单控件,我的服务返回的字段(表单中的员工ID,姓名,部门等)比表单控件更多。如何跳过那些不在窗体控件中使用的控件?

this._employeeService.getEmployeeById(this.employeeId).subscribe((res: Response) => {
        debugger;
        this.employeeForm.get('FileUploader').setValue(null);        
        //this.employeeForm.setValue(res);
        for (const field in res) {
          this.employeeForm.controls[field].setValue(res[field]);
        }
      }); 

this.employeeForm = this._fb.group({
      EmployeeId: 0,
      Name: ''});
Run Code Online (Sandbox Code Playgroud)

angular angular-forms angular6 angular-formbuilder

3
推荐指数
3
解决办法
4459
查看次数

How to run Protractor e2e tests with different environment variables (Angular 6)

In e2e test I want to have environment variable similar to the one as in Angular app. Looks like e2e test project builder "builder": "@angular-devkit/build-angular:protractor" does not support file replacements (unlike builder for web app):

"fileReplacements": [{
  "replace": "apps/web/src/environments/environment.ts",
  "with": "apps/web/src/environments/environment.prod.ts"
}]
Run Code Online (Sandbox Code Playgroud)

So using Angular CLI ng e2e command I can switch configurations (or projects in angular.json) and in project configuration I can specify different Protractor configuration files protractor.conf.js. My question is: how can I get in e2e test …

protractor e2e-testing angular angular6

3
推荐指数
1
解决办法
3880
查看次数

AG-Grid:根据条件在网格中显示某些“操作”按钮

我在Angular 6应用程序中使用的是“ AG Grid”社区版。

我现在面临的挑战是:我有一个相当简单的数据结构,其中的一个列表绑定到网格上进行显示。基于其值,我想在网格中添加“操作”列,以使用户可以访问某些操作,例如删除条目,“升级”它等。

对于单独的数据绑定列,当绑定时,我会获得每一行的相应数据值,例如,可以使用单元格渲染器格式化显示。我希望能够与“动作”列(未绑定到该类的特定数据元素)做类似的事情-但看来我的“动作单元格渲染器”没有任何基础它的决定。

我有一个像这样的数据结构:

export interface Indicator {
    Id: string;
    Name: string;
    IsGlobal: boolean;
}
Run Code Online (Sandbox Code Playgroud)

这些数组Indicators被绑定到OnInit我的Angular组件的功能中的AG网格。

我将AG网格的列定义为:

columnDefs = [
    { headerName: 'Name', field: 'Name', width: 200, editable: true },
    { headerName: 'Global', field: 'IsGlobal', editable: false, width: 100,
      cellRenderer: (data) => { 
        // here, "data" refers to the "IsGlobal" value of the row being displayed
        if (data.value === true) {
          return 'Ja';
        } else {
          return 'Nein';
        }
      },
    }, …
Run Code Online (Sandbox Code Playgroud)

typescript ag-grid angular6

3
推荐指数
1
解决办法
3608
查看次数

角形路由器导航然后重新加载

所以我想导航到特定路线后重新加载应用程序。

我使用router.navigate根据用户角色导航到某些路由,效果很好,但是如果来自登录页面(并非每次用户打开该特定路由),我必须在路由后重新加载页面-此处重新加载是为了更新页面语言取决于用户的语言

所以我想做的是

  else if(this.sp.role === 'Admin') {
      console.log('ooo')
      this.router.navigate(['/admin/dashboard']); 
      this.window.location.reload();
Run Code Online (Sandbox Code Playgroud)

但这会重新加载登录页面

routing angular2-routing angular angular5 angular6

3
推荐指数
4
解决办法
6351
查看次数

如何将angular7降级到angular6

我尝试通过运行以下命令将7号角降级为6npm号角:

npm uninstall -g angular-cli
npm cache clean
npm install -g angular-cli@6.1.1
Run Code Online (Sandbox Code Playgroud)

但是,我的文件中仍显示angular/cli 7版本package.json。我需要帮助以降级angular7为angular6。

npm typescript angular-cli angular6 angular7

3
推荐指数
1
解决办法
3523
查看次数

如何通过与id比较来合并三个不同的数组?在Angular 6中

数组:

 array1 = [{id:1, name:"raju"},{id:2, name:"ravi"},{id:4, name:"john"},{id:6, name:"jack"}];
 array2= [{id:1, degree:"b.com"},{id:3, degree:"b.a"},{id:4, degree:"c.a"},{id:5, degree:"horticulture"}];
 array3= [{id:1, age:20},{id:3, age:21},{id:6, age:27},{id:7, age:25}];
Run Code Online (Sandbox Code Playgroud)

所需结果是:

resultarray = [
    {id:1, name: "raju", degree:"b.com",age:20},
    {id:2, name: "ravi"},
    {id:3, degree:"b.a", age:21},
    {id:4, name:"john", degree:"c.a"},
    {id:5, degree:"horticulture"},
    {id:6, name:"jack", age:27},
    {id:7, age:25}
 ] 
Run Code Online (Sandbox Code Playgroud)

我尝试了不同的功能,并尝试了两个数组,但无法合并没有ID进行比较的对象。

javascript typescript angular6

3
推荐指数
1
解决办法
128
查看次数