09 2019 档案
摘要:angular 中的生命周期: 组件加载时,生命周期函数的执行顺序: 00 -- constructor: 首先执行构造函数,一般用来初始化变量,不应该做其他事情 01 -- ngOnChanges: 当被绑定输入属性的值发生变化时执行,父子组件传值的时候自动调用。没有输入属性值变化,不执行该函数
阅读全文
摘要:1. 子组件调用父组件的方法和数据 -- Input 装饰器 1. fatherComponent.html中 toChildStr -- 父组件中定义的数据 fatherMethod -- 父组件中的方法 fatherComponent -- 父组件本身, this指代父组件实例,通过 [fath
阅读全文
摘要:angular中 父组件调用子组件的方法 -- 使用 @ViewChild 装饰器修饰子组件,获取方法,调用 除此之外 ViewChild 还可以获取 DOM ,操作 DOM , 详见: https://www.cnblogs.com/monkey-K/p/11567098.html 1. html
阅读全文
摘要:ngAfterViewInit(): void { // DOM 加载完成的生命周期函数, 在此处获取 DOM let dom2: any = document.getElementById('dom2') console.log(dom2) dom2.style.color = 'blue' }
阅读全文
摘要:一. canActive 使用场景:导航栏某个标签,如用户设置页面,只有登录才可以查看,不登录则点击无效 说明: canActive--是否能调用当前路由 实现: 1. 创建路由守卫类 import { CanActivate } from '@angular/router' export clas
阅读全文
摘要:1. 路由跳转方式一: /路由?id='001' 方式 -- queryParams 方式 路由配置:{ path: 'details', component: bookDetailsComponent } a. 指令跳转: <a [routerLink]="['/details']" [query
阅读全文
摘要:1. 新建一个app.routing.module.ts 文件,可以手动添加也可以命令生成 (ng generate module app-routing --flat --module=app) import { NgModule } from '@angular/core'; import {
阅读全文
摘要:1. 自定义指令 - @directive import { Component, Directive, HostListener, ElementRef } from '@angular/core' @Directive({ selector: '[input-trim]', host: { '(
阅读全文
摘要:1. angular8.1.1 package.json { "name": "angular-demo", "version": "0.0.0", "scripts": { "ng": "ng", "start": "ng serve", "build": "ng build", "test":
阅读全文