标签: angular6

Angular 6迁移PWA无法正常工作

我最近将我的应用程序迁移到Angular 6,它在角度5中运行良好,我遇到了很多问题,但无论如何我解决了它们,但PWA我无法迁移,在角度5 PWA工作正常,但在6给出以下错误......

当我跑步的时候

    command ng add @angular/PWA  its showing error 
**Error ** 
    target is not defined for the specified project 
Run Code Online (Sandbox Code Playgroud)

请帮助如何在Angular 6中迁移或添加PWA

angular5 angular6

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

Angular 6是否正在删除默认元素边距?

我遇到的问题是Angular 6中的html元素(下面示例中的按钮)似乎缺少默认边距:

Angular 5.2.2示例 - 按钮之间具有默认边距/间距

Angular 6.0示例 - 缺少按钮之间的边距/间距

我希望有人可以确认这是一个有角度的问题 - 或者指出问题的根源 - 在我打开一个github问题之前

html css angular angular5 angular6

2
推荐指数
2
解决办法
1387
查看次数

角模块与库

太棒了,Angular发布了版本6,CLI提供了生成库的选项-他们称其为“备受期待的功能”。

现在,从业务角度来看,我想知道:

  • 为什么您实际上需要这个,
  • 为什么在现有项目中而不是可以通过npm像往常一样安装的单独项目中...
  • 如果您想在项目中使用它,为什么不为此使用模块。

所以我明白了,在npmjs上发布了一些东西,希望整个世界以及未来的连接事物都需要它。图书馆,太好了。

在更大的公司的大型系统中,我们可以重用库,但是我们已经能够使用模块重用东西。我需要分别构建库并在每次更改内容时重新编译。

使用库而不是模块的原因是什么?

(现在我想说,一个lib可以比模块更大,所以我只是用它来组织我的应用程序更好)

angular-cli angular angular-library angular6 angular-cli-v6

2
推荐指数
2
解决办法
4183
查看次数

角度材质扩展面板错误 - TypeError:this.driver.containsElement不是函数

Angular材质的扩展面板取决于BrowserAnimationsModule.我已经包含了动画模块,但是当我创建一个简单的扩展面板时,它崩溃并出现错误:

错误TypeError:this.driver.containsElement不是TransitionAnimationEngine.push ../ node_modules上TransitionAnimationEngine.push ../ node_modules/@angular/animations/fesm5/browser.js.TransitionAnimationEngine._balanceNamespaceList( browser.js:2765)的函数.在TransitionAnimationEngine.push ../node_modules/@angular/animations/fesm5/browser.js.TransitionAnimationEngine.register(browser.js:/@angular/animations/fesm5/browser.js.TransitionAnimationEngine.createNamespace( browser.js:2743) 2784)在InjectableAnimationEngine.push ../ node_modules/@angular/animations/fesm5/browser.js.AnimationEngine.register(browser.js:3815),在AnimationRendererFactory.push ../ node_modules/@ angular/platform-b​​rowser/fesm5/createComponentView(core.js)上的DebugRendererFactory2.push ../ node_modules/@angular/core/fesm5/core.js.DebugRendererFactory2.createRenderer(core.js:12225)的animations.js.AnimationRendererFactory.createRenderer(animations.js:140) :11179)在Object.de的callWithDebugContext(core.js:12204)createViewNodes上的bugCreateComponentView [as createComponentView](core.js:11715)(core.js:11220)

home.component.html

<div class="container-fluid">
    <div id="sidebar">
        <mat-expansion-panel>
            <mat-expansion-panel-header>
              <mat-panel-title>
                This is the expansion title
              </mat-panel-title>
              <mat-panel-description>
                This is a summary of the content
              </mat-panel-description>
            </mat-expansion-panel-header>
            <p>This is the primary content of the panel.</p>
          </mat-expansion-panel>
    </div>
    <div id="map" style="height: 550px"></div>
</div>
Run Code Online (Sandbox Code Playgroud)

home.module.ts

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { TranslateModule } from '@ngx-translate/core';

import { …
Run Code Online (Sandbox Code Playgroud)

angular-ui angular-material angular angular-animations angular6

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

ngx-datatable下拉菜单中的ng-select不可见

(我在这里转载我的问题:https : //plnkr.co/QvEWjhJhbsghy1OD)

<ng-select>选项的下拉列表未显示在该<ngx-datatable>行的上方,似乎已被单元格的高度削减,使其变得毫无用处。

切断ng-select

常规<select>效果很好,但我可以看到所有选项。

工作常规选择

如何使ng-select正常工作?

angular-ngselect ngx-datatable angular6

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

带有数据源的角度材质表:分页和过滤器不起作用

我有以下具有数据源属性的角度材质表:

<div class="dim">
  <mat-form-field >
    <input matInput class="warn" (keyup)="applyFilter($event.target.value)" placeholder="Search">
    <mat-icon matSuffix>search</mat-icon>
  </mat-form-field>
</div>
<div class="mat-elevation-z2">
  <table mat-table [dataSource]="dataSource" matSort>
    <ng-container matColumnDef="unit_id">
      <th mat-header-cell *matHeaderCellDef mat-sort-header>ID</th>
      <td class="alignTd" mat-header *matCellDef="let row">{{row.id}}</td>
    </ng-container>

    <ng-container matColumnDef="unit_type">
      <th mat-header-cell *matHeaderCellDef mat-sort-header>Type</th>
      <td mat-header *matCellDef="let row">{{row.unit_type}}</td>
    </ng-container>

    <ng-container matColumnDef="location_id_auto">
      <th mat-header-cell *matHeaderCellDef mat-sort-header>Location</th>
      <td mat-header *matCellDef="let row">{{row.location}}</td>
    </ng-container>

    <ng-container matColumnDef="user_id">
      <th mat-header-cell *matHeaderCellDef mat-sort-header>User</th>
      <td mat-header *matCellDef="let row">{{row.user}}</td>
    </ng-container>

    <ng-container matColumnDef="unit_number_hh">
      <th mat-header-cell *matHeaderCellDef mat-sort-header>Number Of units</th>
      <td mat-header *matCellDef="let row">{{row.unit_number}}</td>
    </ng-container>

    <ng-container matColumnDef="unit_status"> …
Run Code Online (Sandbox Code Playgroud)

pagination datasource angular angular6 angular-material-6

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

错误TS2307:在moment-date-adapter.d.ts中找不到模块“ moment”

使用Angular 6,我在使用材料力矩适配器时遇到了麻烦。在我的moment-date-adapter.d.ts文件中,当尝试从中导入{Moment}时,在导入语句中显示“找不到'module'”

node_modules/@angular/material-moment-adapter/typings/adapter/moment-date-adapter.d.ts。

我的tsconfig.json如下:

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "module": "es2015",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ] 
  }
}
Run Code Online (Sandbox Code Playgroud)

我的进口声明很简单

import { Moment } from 'moment';
Run Code Online (Sandbox Code Playgroud)

从我的moment-date-adapter.d.ts文件中。

任何帮助,将不胜感激。

material-design angular-material angular angular6

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

Angular 6中输入和跨度之间的文本绑定

如何在Angular6中绑定输入文本以跨越innerHTML?

ts文件

...
finance_fullname: string;
...
Run Code Online (Sandbox Code Playgroud)

模板文件

<input type="text" id="finance_fullname" [(ngModel)]="finance_fullname">
<span class="fullname" ngBind="finance_fullname"></span>
Run Code Online (Sandbox Code Playgroud)

data-binding angular angular6

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

服务在APP_INITIALIZER之后实例化两次

问题是:我需要进行http调用并存储生成动态路由所需的对象。因此,我正在利用APP_INITIALIZER。

// app.module.ts
import { ApplicationService } from './application.service';


providers: [
  ApplicationService,
  { 
  provide: APP_INITIALIZER, useFactory: appServiceFactory, deps: 
  [Injector, ApplicationService], multi: true 
  },
],

function appServiceFactory(injector: Injector, appService: ApplicationService): Function {
  return () => {
    return appService.loadApplication().then((app: Application) => {
      /custom logic
      });
    });
  };
}


// application.service.ts
@Injectable({
  providedIn: 'root'
})

// navigation.component.ts
import { ApplicationService } from './application.service';

export class NavigationComponent implements OnInit {

    constructor(private _applicationService: ApplicationService) {
  }
Run Code Online (Sandbox Code Playgroud)

}

但是在navigation.component内部,再次初始化applicationservice。我敢肯定,因为如果我记录或放置调试器语句,则该服务的Construct()方法将被调用两次。

为什么即使将Service声明为Singleton并providedIn: root重新实例化?

singleton dependency-injection angular angular6

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

来自Angular 6中动态创建的组件的@Output

在我的angular 6项目中,我有一个动态创建的组件,如下所示:

@Component({
    selector: 'app-staff-dash',
    template: `
    <template #tasksContainer></template>
`
})

export class StaffDashComponent implements OnInit {

    componentRef: any;
    factory: any;
    @ViewChild('tasksContainer', { read: ViewContainerRef }) tasksEntry: ViewContainerRef;


    constructor(
        @Inject(ComponentFactoryResolver) private resolver: ComponentFactoryResolver
    ) {

    }

    ngOnInit() {
        this.createTasksComponent();
    }


    createTasksComponent(): void {
        this.tasksEntry.clear();
        this.factory = this.resolver.resolveComponentFactory(TasksComponent);
        this.componentRef = this.tasksEntry.createComponent(this.factory);
    }
}
Run Code Online (Sandbox Code Playgroud)

StaffDashComponent是父母,TasksComponent是孩子。现在,我希望将一些数据从传递TasksComponent到StaffDashComponentusing @Output。我该如何实现?

angular angular6

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