小编sha*_*mat的帖子

如何在Angular4中访问Component的nativeElement?

我有两个组件,一个有属性选择器.子组件是,

import { Component, OnInit, Input, ElementRef } from '@angular/core';


@Component({
    selector: '[app-bar-chart]',
    templateUrl: './bar-chart.component.html',
    styleUrls: ['./bar-chart.component.css']
})
export class BarChartComponent implements OnInit {

    @Input() chartContainer: ElementRef;
    @Input() title: string;
    @Input() chartData: {
        title: string,
        content: {
            label: string,
            value: number,
            fill?: string
        }[]
    }[];

    constructor() { }

    ngOnInit() {
        console.log(this.chartContainer);
        console.log(this.chartContainer.nativeElement);
    }

}
Run Code Online (Sandbox Code Playgroud)

父组件是,

import { Component, OnInit, Output, ViewChild, ElementRef } from '@angular/core';

@Component({
    selector: 'app-dashboard',
    template: `<div><div class="graph-image" style="width: 100%; height: 400px;" app-bar-chart [title]="barChartTitle" [chartData]="ChartData" [chartContainer]="chartContainer" #chartContainer></div></div>`, …
Run Code Online (Sandbox Code Playgroud)

angular

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

重置表单后,Angular 4被动表单不会清除验证

我在我的应用程序中使用Angular 4.4.6反应形式和Angular Material 2.0.0-beta.12.这是我的组成部分,

import { Component, OnInit } from '@angular/core';
import { FormGroup, FormControl, Validators } from '@angular/forms';

@Component({
    selector: 'app-quick-file',
    templateUrl: './quick-file.component.html',
    styleUrls: ['./quick-file.component.css']
})
export class QuickFileComponent implements OnInit {

    quickFileForm: FormGroup;


    constructor() { }

    ngOnInit() {
        this.initQuickFileForm();
    }

    private initQuickFileForm () {
        this.quickFileForm = new FormGroup({
            'fileOpenDate': new FormControl(new Date(), Validators.required),
            'fileSubjectEn': new FormControl(null, Validators.required),
            'categoryId': new FormControl(null, Validators.required),
            'subCategoryId': new FormControl(null),
            'primaryClientId': new FormControl(null, Validators.required),
            'primaryConsultantId': new FormControl(null, Validators.required)
        });
    }

    saveQuickFileForm() {
        console.log(this.quickFileForm);
        this.quickFileForm.reset(); …
Run Code Online (Sandbox Code Playgroud)

angular

7
推荐指数
1
解决办法
5094
查看次数

类型错误:c[a] 在 CKEditor 中未定义

我正在使用 $.getScript 加载 ckeditor.js 文件,并在回调中启动 CKEditor。但它显示了一个错误 TypeError: c[a] is undefined。这是我的代码。我该如何解决这个问题?

$.getScript("ckeditor.js", function (data, textStatus, jqxhr) {
    if (textStatus == 'success' && jqxhr.status == 200) {
        CKEDITOR.replace( 'commentBox',
        {
            toolbar :
            [
                { name: 'basicstyles', items : [ 'Bold','Italic','Underline','Strike','Subscript','Superscript','-','RemoveFormat' ] },
                { name: 'paragraph', items : [ 'NumberedList','BulletedList','-','Blockquote'] },
                { name: 'insert', items : [ 'Table','HorizontalRule','SpecialChar' ] },

                { name: 'styles', items : [ 'Styles','Format','Font','FontSize' ] },
                { name: 'colors', items : [ 'TextColor','BGColor' ] }
            ]
        });
    }
});
Run Code Online (Sandbox Code Playgroud)

javascript jquery ckeditor

5
推荐指数
1
解决办法
3756
查看次数

如何使用异步管道形式 mat-option 值?

我正在使用 Angular Material 5 处理 Angular 5 项目。在我的一个表单中,我必须从 Web 服务中获取下拉值。这就是我声明表单数据的方式,

formData:Observable<{
    taxList: {
    label: string,
        Value: number
    }[],
    category: {
        label: string,
        Value: number
    }[]
}>;
Run Code Online (Sandbox Code Playgroud)

ngOnInit我获取数据如下。

this.dataService.getFormData().subscribe((data) => {
    this.formData = data.content;
});
Run Code Online (Sandbox Code Playgroud)

在我的模板中,

<mat-form-field class="common-form-field">
    <mat-select formControlName="taxId">
        <mat-option *ngFor="let tax of (formData.taxList | async)" [value]="tax.value">
            {{ tax.label }}
        </mat-option>
    </mat-select>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)

我得到在控制台中的错误,Cannot read property 'taxList' of undefined以及InvalidPipeArgument: '[object Object],[object Object]' for pipe 'AsyncPipe' 什么是错误和可能的解决方案?谢谢

angular

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

如何使用AJAX实现Angular Material 2自动完成功能

我在Angular 4项目中使用Angular Material 2 Autocomplete.在此示例中,如何实现自动完成值从HTTP调用加载?

任何人都可以给我一个Plunker演示吗?谢谢

angular-material2 angular

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

直接在模板中绑定 scrollTop 会出错

我正在处理一个 Angular 5 项目。在我的项目中,我有类似元素的聊天框。我在 a 中列出评论ul,其高度固定为overflow-y: auto. 就像一个标准的聊天框,我必须显示这个可滚动的最底部ul。因此,当添加新评论时,它将出现在底部,ul我必须滚动到底部。为了实现这一目标,我绑定scrollTop的这个属性ulscrollHeight如下,

<ul class="comment-list" #commentEl [scrollTop]="commentEl.scrollHeight">
    <li *ngFor="let comment of comments">{{ comment }}</li>
</ul>
Run Code Online (Sandbox Code Playgroud)

ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: '851'. Current value: '0'初始化此组件并销毁此组件时出现错误。我该如何解决这个问题?

angular

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

如何在Angular 6中创建震动动画?

我们如何使用Angular 6动画创建摇动动画?该动画应看起来像是“摇动”动画Animate.css

angular angular-animations

-1
推荐指数
1
解决办法
1793
查看次数