Angular4.x 各种坑持续更新

1、如果ngFor 或者 ngIf等指令不识别,请在路由中引入,且加入

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

@ NgModule中
imports:[
CommonModule
]

2、如果下拉框等不出现,需要引入

import { BsDropdownModule } from 'ngx-bootstrap/dropdown';


3、ngbModal open()参数传递

子页面import { Component, Output, EventEmitter } from '@angular/core';
export class AppModalComponent {
    private data: string;
    @Output emitService = new EventEmitter();

    constructor() {
        this.data = "hello world";
    }        ngOnInit(){        // 坑,父传子的数据,在init中可以获取, constructor()无法获取
    }

    addMe() {
        this.emitService.next(this.data)
    }
}

父页面openModal() {
     const modalRef = this.modalService.open(AppModalComponent);     // 父传子
     modalRef.componentInstance.data = 'hi';
     // 子传父:
     modalRef.componentInstance.emitService.subscribe((emmitedValue) => {
         // do sth with emmitedValue
     });
}

猜你喜欢

转载自blog.csdn.net/strong90/article/details/79924045