标签: angular6

"mat-form-field"中的Angular 6错误显示不是已知元素:

嗨我使用角度6,我的代码如下:

import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule, Routes } from '@angular/router';




import { AppComponent } from './app.component';
import { AppRoutingModule } from './app.routing.module';


import { MatButtonModule, MatFormFieldModule, MatInputModule, MatRippleModule } from '@angular/material';
//import { MaterialModule } from 'src/app/et-shared/material.module';


const modules = [
  MatButtonModule,
  MatFormFieldModule,
  MatInputModule,
  MatRippleModule
];

@NgModule({
  declarations: [
    AppComponent,
  ],
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    CommonModule,
    RouterModule,
    AppRoutingModule, …
Run Code Online (Sandbox Code Playgroud)

angular-material angular angular6

8
推荐指数
3
解决办法
5万
查看次数

rxjs:EmptyError:序列中没有元素

我收到了一个错误

当我转到localhost:8080时,'EmptyError:序列中没有元素'错误.

我看到了线程Angular 5 EmptyError:在制作子路由时没有顺序的元素,但似乎没有任何答案适用.

我有"rxjs": "^5.5.6",在我的路线中,我尝试添加,pathMatch: 'full',但仍然显示错误.

我的app-routing-module.ts的摘录

const routes: Routes = [
    {
        pathMatch: 'full', /* added recently for test purposes*/
        path: '',
        component: RootComponent,
        canActivate: [AuthGuard],
        children: [
            {
                pathMatch: 'full', /* added recently for test purposes*/
                path: '',
                component: RootLoggedComponent
            },
Run Code Online (Sandbox Code Playgroud)

这只发生在最近,我添加了一个http拦截器:

export class myInterceptor implements HttpInterceptor {
    constructor(
        private router: Router
    ) {

    }

    intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {

        return next.handle(request)
            .pipe(catchError(err => {
                if (err …
Run Code Online (Sandbox Code Playgroud)

rxjs angular angular6

8
推荐指数
1
解决办法
2480
查看次数

带界面的Angular 6服务

我正在使用Angular(6.0.7)构建应用程序,并且尝试使用新的创建服务:

@Injectable({
  providedIn: 'root'
})
Run Code Online (Sandbox Code Playgroud)

但是,如何使用接口键入注入?


问题

我有2个服务,Authentication.service和SessionStorage.service。我想将sessionstorage注入到身份验证服务中。可以通过以下方式完成:

constructor(private sessionStorage: SessionStorage) {
}
Run Code Online (Sandbox Code Playgroud)

没问题。但是出于面向对象的目的,我希望interface在此服务之上(这样我就可以将localstorage服务都实现为sessionstorage服务)。因此,我想用接口键入注入的类是合乎逻辑的,但这不能以与Angular 5及更低版本相同的方式完成。

那么,如何通过界面在该全局服务中键入注入?


我试过了

Angular服务类型描述了InjectableProvider,但是与的兄弟姐妹的任何参数都不匹配InjectableProvider,因此这会产生编译器(和tslint)错误。

@Injectable({
  providedIn: 'root'
}, {provide: IStorageService, useClass: SessionStorage})
Run Code Online (Sandbox Code Playgroud)

service dependency-injection typescript angular angular6

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

什么是可观察的,观察者和有角度的订阅?

我正在学习角度,我对这些可观察,观察和订阅的事情感到困惑.所以请解释一下.

rxjs rxjs5 angular angular6

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

选择所有垫选项并取消选择全部

我的情况如下:

在此输入图像描述

我想要实现的是:

  1. 当用户单击All时,将选择所有选项,当用户再次单击All时,将取消所有选项.
  2. 如果所有选项被选中,并单击用户比任何其他复选框, All然后所有,并点击复选框将被取消.
  3. 当用户逐个选择4个选项时,则选择All.

HTML文件

<mat-select placeholder="User Type" formControlName="UserType" multiple>
    <mat-option *ngFor="let filters of userTypeFilters" [value]="filters.key">
          {{filters.value}}
    </mat-option>
        <mat-option #allSelected (click)="toggleAllSelection()" [value]="0">All</mat-option>
</mat-select>
Run Code Online (Sandbox Code Playgroud)

TS文件

this.searchUserForm = this.fb.group({
  userType: new FormControl('')
});

userTypeFilters = [
  {
    key: 1, value: 'Value 1',
  },
  {
    key: 2, value: 'Value 2',
  },
  {
    key: 3, value: 'Value 3',
  },
  {
    key: 4, value: 'Value 4',
  }
]

toggleAllSelection() {
  if (this.allSelected.selected) {
    this.searchUserForm.controls.userType …
Run Code Online (Sandbox Code Playgroud)

multi-select angular-material2 angular6

8
推荐指数
4
解决办法
2万
查看次数

Ag-grid 工具提示仅在省略号文本上方

我在我的项目中使用企业ag-Grid版本。
我在盒子下面找到了工具提示支持,并按如下方式制作:

columnDefs = [
{
    headerName: 'USER NAME',
    field: 'userName',
    sortingOrder: ['asc', 'desc'],
    filter: 'agTextColumnFilter',
    filterParams: {newRowsAction: "keep"},
    floatingFilterComponentParams: {suppressFilterButton: true},
    suppressMenu: true,
    tooltip: (t: any) => { return t.value; }
}, //...
];
Run Code Online (Sandbox Code Playgroud)

工具提示工作正常并显示在我的网格中“ userName ”列的每个单元格上方。
如果文本仅为省略号,是否可以在标题/单元格上方显示工具提示?

提前致谢。

javascript ag-grid ag-grid-ng2 angular6

8
推荐指数
1
解决办法
2283
查看次数

Ng 测试 - 无法绑定到“value”,因为它不是“mat-select”的已知属性

我有一个使用 Material Design 的 Angular6 应用程序。运行“ng test”时,出现以下错误:

失败:模板解析错误:无法绑定到“value”,因为它不是“mat-select”的已知属性。

我在导入和导出中包含了 MatSelectModule。它在应用程序中运行良好,但在测试期间失败。

material-design.module.ts

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

import { MatFormFieldModule, MatInputModule, MatSelectModule} from '@angular/material';

@NgModule({
  imports: [MatFormFieldModule, MatInputModule, MatSelectModule],
  exports: [MatFormFieldModule, MatInputModule, MatSelectModule],
})
export class MaterialDesignModule { }
Run Code Online (Sandbox Code Playgroud)

选择示例:

<mat-form-field class='select_buttons'>
  <mat-select (selectionChange)='typeSelection_changed($event)' [(value)]='type'>
    <mat-option *ngFor="let type of types" [value]="type"> {{type.name}}</mat-option>
  </mat-select>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)

testing angular-material angular-cli angular6

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

没有 index.html 的 Angular CLI 构建

我们所有的 Angular 应用程序都在其他应用程序中引导(.jsp加载 javascript 文件并包含<app-root>标签的文件),所以我们不需要index.html**.

但是,当我index从我们的属性中删除angular.json它时,它给了我错误:

数据路径“”应该具有必需的属性“索引”。

如果我将其留空,它确实会构建,但会出现错误:

...
95% 发出 index-html-webpack-pluginEISDIR:对目录的非法操作,读取
错误:EISDIR:对目录的非法操作,读取

我如何在ng build没有 的情况下执行index.html?

** 我们的部署过程现在实际上将 复制index.html到我们的 CDN 中,这是不需要的,因为我们根本不想将这些文件提供给最终用户,index.html仅用于开发人员在ng serve

angular-cli angular angular6 angular-cli-v6

8
推荐指数
1
解决办法
5136
查看次数

Angular6:使用本地库时没有注入器的提供者

我对 AngularJS 发布后的 Angular 版本有点陌生,并决定尝试一下。我想要做的是构建一个 UI 组件库,以及一个将使用所述库的应用程序。在我的库中,我决定将组件创建为 WebComponents,所以按照我目前找到的教程,我有类似的东西

import { Injector, NgModule } from '@angular/core'
import { createCustomElement } from '@angular/elements';
import { MyButtonComponent} from './my-button.component'

@NgModule({
    declarations: [MyButtonComponent],
    entryComponents: [MyButtonComponent]
})
export class MyButtonModule {
    constructor(injector: Injector) {
        const myButton = createCustomElement(MyButtonComponent, { injector });
        customElements.define('my-button', myButton);
    }
}
Run Code Online (Sandbox Code Playgroud)

对于我的自定义组件。如果我将组件的所有文件(模块、组件、模板和 SCSS 文件)直接添加到我的应用程序中,它会按预期工作,所以我知道我的组件声明是正确的。但是,如果在我的应用程序中包含库中的组件,则在使用 运行我的应用程序时ng serve,我会看到错误:

Error: StaticInjectorError(AppModule)[MyButtonModule -> Injector]: 
  StaticInjectorError(Platform: core)[MyButtonModule -> Injector]: 
    NullInjectorError: No provider for Injector!
Run Code Online (Sandbox Code Playgroud)

我正在使用 Angular 6,并且我的两个项目都在本地运行,并且我正在使用ng-packagr捆绑我的库。我在我的库中添加了@angular/coreand @angular/elementsaspeerDependencies …

angular angular6

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

Angular/Typescript - 通配符模块声明

我正在尝试实现通配符模块,我似乎没有得到它的工作:

现在我有以下代码可行:

typings.d.ts

declare module "*.json" {
  const value: any;
  export default value;
}
Run Code Online (Sandbox Code Playgroud)

app.component.ts

import { Component, OnInit } from '@angular/core';
import * as es from './i18n/es.json';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ]
})
export class AppComponent implements OnInit {
  hello = '-';

  ngOnInit() {
    this.hello = es.default.hello;
  }
}
Run Code Online (Sandbox Code Playgroud)

您可能会看到一个活生生的例子在这里,但是我想实现通配符,因为看到这里(typescriptlang)和这里(SitePen接触): 在此输入图像描述

实现应该允许我做这样的事情:

typings.d.ts

declare module "*.json!i18n" {
  const value: any;
  export default value;
}

declare module "*.json!static" { …
Run Code Online (Sandbox Code Playgroud)

typescript angular-module angular angular6 angular7

8
推荐指数
1
解决办法
863
查看次数