标签: angular6

角度6.1 StaticInjectorError

当我在angular ng serve中运行cmd时,应用程序停止加载,并且出现以下错误。

错误错误:未捕获(承诺):错误:StaticInjectorError(AppModule)[AuthService-> Http]:StaticInjectorError(平台:core)[AuthService-> Http]:NullInjectorError:没有Http的提供者!错误:StaticInjectorError(AppModule)[AuthService-> Http]:StaticInjectorError(平台:core)[AuthService-> Http]:NullInjectorError:没有Http的提供程序!在NullInjector.push ../ node_modules/@angular/core/fesm5/core.js.NullInjector.get(core.js:979)在resolveToken(core.js:1232)

angular angular6

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

Angular 6 - rxjs管道不能处理valueChanges

我有一个反应形式,带有文本输入.为了便于访问我的打字稿,我声明:

get parentId(): FormControl {
    return this.addForm.get("parentId") as FormControl;
}
Run Code Online (Sandbox Code Playgroud)

这部分工作,控件被正确访问.

现在我的ngOnInit如果我这样做:

this.parentId.valueChanges.subscribe(() => console.log("Changed"));
Run Code Online (Sandbox Code Playgroud)

正如预期的那样,在输入中更改的每个字符处执行控制台日志.但如果我这样做:

this.parentId.valueChanges.pipe(tap(() => console.log("Changed")));
Run Code Online (Sandbox Code Playgroud)

什么都没发生.没有错误,没有任何错误.我也尝试过使用map,switchMap等等.似乎管道对valueChanges不起作用.我在我的代码中的其他地方使用管道方法在不同的observables上没有任何问题.

我需要在这里使用管道去抖动,映射等.

知道我做错了什么吗?

- 编辑 -

这是Angular Material网站上的自动填充组件的代码示例:

ngOnInit() {
   this.filteredOptions = this.myControl.valueChanges
       .pipe(
          startWith(''),
          map(val => this.filter(val))
       );
}
Run Code Online (Sandbox Code Playgroud)

最后没有订阅,示例有效.

observable rxjs angular angular6

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

TypeError:this.http.post(...).map在更新角度5到角度6之后不是函数

在将Angular 5更新为Angular 6之后,我遇到了一些关于rxjs6的问题:

TypeError: this.http.post(...).map is not a function

error TS2339: Property 'map' does not exist on type 'Observable<Object>'.

TypeError: rxjs__WEBPACK_IMPORTED_MODULE_1__.Observable.of is not a function
Run Code Online (Sandbox Code Playgroud)

我尝试过一些方法,比如:

将此导入添加到service.ts

从'rxjs/operators'导入{map};

更改http.post().pipe(map(res => {...}))

然而,所有这些都不适合我.

我的环境如下:

 "@angular/cli": "^6.0.3"
 "rxjs": "^6.2.0"
 "rxjs-compat": "^6.2.0"
Run Code Online (Sandbox Code Playgroud)

代码显示如下 Service.ts

import { Injectable } from '@angular/core';
import {environment} from '../../environments/environment';
import {HttpClient} from '@angular/common/http';
import {StorageService} from '../services/storage.service';

@Injectable()
export class VariationService {
ip = environment.url.management;
constructor(private http: HttpClient,
            private storageService: StorageService) { }
getFlowChart(status?) {
    status = status …
Run Code Online (Sandbox Code Playgroud)

rxjs angular angular6 rxjs6

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

角度6错误ReferenceError:与elasticsearch js“未定义过程”

在一切之前,我读到:

有关流程的问题1未定义

关于流程的问题2未定义

角度5问题

浏览器版本信息

所提供的信息均无济于事。我正在使用Angular 6,我想使用elasticsearch js将查询发送到elasticsearch。我安装了elasticsearch,弹性类型和弹性浏览器,如下所示:

npm install elasticsearch
npm install @types/elasticsearch
npm install elasticsearch-browser
Run Code Online (Sandbox Code Playgroud)

我尝试使用--save和--save-dev进行安装,但都没有成功。

然后,我创建了一个带有角度cli的新项目:

import { Component } from '@angular/core';
import { Client } from "elasticsearch";

@Component({
  selector: 'app-root',
  template: `
<script src="/node_modules/elasticsearch/src/elasticsearch.js"></script>
  <div class="container">
  <div class="row">
      <button type="" (click)="onSendElastic()">Click Me!</button>
  </div>
</div>`,
  styleUrls: ['./app.component.css']
})
export class AppComponent {

  elClient: Client

  onSendElastic(){
    console.log('clicked on send elstic');
    this.connect()
    let res = this.elSearch()
    console.log(`res: ${res}`);

  }

  connect(){
    console.log('start connect...');

    this.elClient = new Client({
      host:"http://elasticIp:9200",
      log:"trace"
    }) …
Run Code Online (Sandbox Code Playgroud)

javascript node.js elasticsearch angular angular6

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

Bootstrap在Angular 6应用程序中不起作用

我想在Angular 6应用程序中使用Bootstrap,这是我到目前为止所做的,但似乎没有任何工作:

1)使用npm安装bootstrap,jquery和popper.js.2)在Angular.json文件中输入以下内容

"styles": [
    "src/styles.scss",
    "node_modules/bootstrap/scss/bootstrap.scss"
],
"scripts": [
    "node_modules/jquery/dist/jquery.slim.min.js",
    "node_modules/popper.js/dist/umd/popper.min.js",
    "node_modules/bootstrap/dist/js/bootstrap.min.js"
    ...
]
Run Code Online (Sandbox Code Playgroud)

我错过了什么.这似乎没有成功.

jquery twitter-bootstrap bootstrap-4 angular angular6

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

多个路由器出口丢失url参数

我正在构建一个应有两个特定路由器出口的angular 6应用程序:

<router-outlet name="navbar"></router-outlet>
<router-outlet></router-outlet>
Run Code Online (Sandbox Code Playgroud)

该应用程序由URL中指定的令牌驱动:

http://my.app/*token*/dashboard
Run Code Online (Sandbox Code Playgroud)

所以我有这个特定的路由:

const routes: Routes = [
    {
        path: ':token', component: CoreComponent, children: [
            { path: 'dashboard', component: DashboardComponent },
            { path: 'app1', component: App1Component },
            { path: 'app2', component: App2Component },
            { path: '', component: NavbarComponent, outlet: 'navbar' }
        ]
    }
];

@NgModule({
    imports: [
        CommonModule,
        RouterModule.forRoot(routes)
    ],
    exports: [RouterModule],
    declarations: []
})
Run Code Online (Sandbox Code Playgroud)

在每个组件中,我都从URL中检索token参数并对其进行一些检查。

constructor(public route: ActivatedRoute,
    public router: Router) {

}

ngOnInit() {
    this.route.params.subscribe(params => {
        let _token: string = …
Run Code Online (Sandbox Code Playgroud)

routing router-outlet angular angular6

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

CKEditor 5抛出无法读取Angular6项目中未定义的属性“创建”

我是angular6的新手。我已经使用JHipster创建了一个项目,并试图使用CKEditor 5创建一个WYSIWYG富文本编辑器。我已经通过使用以下链接来创建编辑器,完成了以下步骤。

  1. npm install --save-dev @ ckeditor / ckeditor5-angular
  2. npm install --save-dev @ ckeditor / ckeditor5-build-classic
  3. 导入@ ckeditor / ckeditor5-angular并在我的module.js中添加导入
  4. 导入@ ckeditor / ckeditor5-build-classic并创建一个变量public Editor:ClassicEditor; 在我的组件中
  5. 在html中使用以下代码

块引用

<ckeditor [editor]="Editor" data="<p>Hello world!</p>"></ckeditor> 
Run Code Online (Sandbox Code Playgroud)

当我转到该页面时,我添加了以下错误,该错误是从浏览器开发人员工具控制台获得的。

ERROR TypeError: Cannot read property 'create' of undefined
    at CKEditorComponent.createEditor (ckeditor-ckeditor5-angular.js?076d:187)
    at eval (ckeditor-ckeditor5-angular.js?076d:96)
    at ZoneDelegate.invoke (zone.js?d135:388)
    at Zone.run (zone.js?d135:138)
    at NgZone.runOutsideAngular (core.js?09c9:3784)
    at CKEditorComponent.ngAfterViewInit (ckeditor-ckeditor5-angular.js?076d:95)
    at callProviderLifecycles (core.js?09c9:9568)
    at callElementProvidersLifecycles (core.js?09c9:9542)
    at callLifecycleHooksChildrenFirst (core.js?09c9:9532)
    at checkAndUpdateView (core.js?09c9:10468)
Run Code Online (Sandbox Code Playgroud)

我只是想知道这是CKEditor 5的问题还是我错过了任何步骤?

任何帮助/方向来解决这个问题,将不胜感激!

ckeditor5 angular6

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

角6链接到其他组件中的部分?

我有一个带有以下代码的导航栏组件:

 <ul class="navbar-nav mx-auto">
              <li class="nav-item active">
                <a class="nav-link" href="#" >Inicio <span class="sr-only"></span></a>
              </li>
              <li class="nav-item active">
                <a class="nav-link" href="#">Here Link Home Section 2 <span class="sr-only"></span></a>
              </li>


</ul>
Run Code Online (Sandbox Code Playgroud)

并具有包含三个部分的另一个组件HomeComponent:

<section id="home_one">
    stuff 
    section
    one
</section>

<section id="home_two">
   stuff 
   section
   two
</section>

<section id="home_three">
    stuff 
    section
    three
</section>
Run Code Online (Sandbox Code Playgroud)

如何从导航栏链接链接到另一个组件(homeComponent)中的特定部分(第2部分)?

html angular angular6

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

Angular 6 numberonly指令不起作用

我已经从https://www.davebennett.tech/angular-4-input-numbers-directive/创建了一条指令,以便可以限制用户仅在电话号码中输入数字。在src/app/app.sharerd.module.ts文件中,我做了以下代码来导入指令:

import { NumberOnlyDirective } from './number.directive';
declarations: [..., ..., NumberOnlyDirective], ...
export class SharedModule { }
Run Code Online (Sandbox Code Playgroud)

现在,在/src/文件夹下,我创建了名为的文件夹modules/auth/component/。

在auth.module.ts该/src/auth/文件夹下,我已执行以下操作:

import { NgModule } from '@angular/core';
import { SharedModule } from '../../app/app.shared.module';
...
...
Run Code Online (Sandbox Code Playgroud)

现在,在signup.html下面/src/auth/component/:

<input type="text" name="phone" myNumberOnly ... > ...
...
Run Code Online (Sandbox Code Playgroud)

我仍然可以在文本框中输入字符/特殊字符等,但是在console / cli中没有看到任何错误。

angular-directive angular angular6

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

遍历对象并将其显示在表Angular 6中

我有一个看起来像这样的对象:

obj = {'a': [0, 0, 1, 0], 'b': [1, 0, 0, 1], 'c': [0, 0, 0, 0], 'd': [1, 1, 1, 0]}
Run Code Online (Sandbox Code Playgroud)

我想在这样的表中显示它:

No   | a | b | c | d 
0    | 0 | 1 | 0 | 1
1-3  | 0 | 0 | 0 | 1
4-6  | 1 | 0 | 0 | 1
7-9  | 0 | 1 | 0 | 0
      //a //b //c //d
Run Code Online (Sandbox Code Playgroud)

我该如何使用ngFor?

这是我的html

<table>
  <thead>
    <tr> …
Run Code Online (Sandbox Code Playgroud)

html ngfor angular angular6

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