
angular
前端自由人
这个作者很懒,什么都没留下…
展开
-
angular如何操作节点修改样式
文章目录angular如何操作节点修改样式angular如何操作节点修改样式一、 直接操作DOM(不推荐)// 获取DOM节点@ViewChildren('img') imgs: QueryList<ElementRef>this.imgs.forEach(item => { item.nativeElement.style.height = "100px" });二、 Renderer2方法(推荐:可以防止代码注入攻击)import { Rendere原创 2021-03-27 23:47:20 · 827 阅读 · 0 评论 -
ViewChild和ViewChildren的使用
文章目录ViewChildViewChildrenViewChild第一种:获取DOM<div #box>一个盒子</div>import {AfterViewInit,ViewChild,ElementRef} from '@angular/core';// static默认false,是否需要提前拿到,静态的和没ngif的可以设置为true@ViewChild('box',{static:true}) private boxel:ElementRef;ngAf原创 2021-03-16 16:23:43 · 1548 阅读 · 0 评论 -
ngStyle和ngClass使用
文章目录属性形式NgStyleNgClass其它ngNonBindable属性形式[style.属性值]<button [style.color]="'red'">bbbb</button><button [style.color]="false ? 'red' : 'blue'">blue</button>带单位的<button [style.font-size.px]="20">哈哈</button><原创 2021-03-14 18:42:23 · 233 阅读 · 0 评论 -
angular路由学习
angular路由学习目录简单路由使用1.导入和注册路由2.组件使用路由通配符路由路由重定向参数路由子路由嵌套路由模块函数式路由路由传参路由守卫简单路由使用1.导入和注册路由app.module.ts文件③④可以抽出来写---①import { RouterModule,Routes } from "@angular/router"; ---④导入组件import { TimComponent } from './tim/tim.component';import { HugoCo原创 2021-03-14 06:27:42 · 351 阅读 · 1 评论 -
angular的httpClient使用
ng的httpClient发送请求库如何使用httpClient发送请求1. 全局注册: app.module.ts2. 组件使用成功方法3. http获取错误处理2种方法:请求非JSON数据GET传参POST传参重试失败的请求retry()如何使用httpClient发送请求1. 全局注册: app.module.tsimport { HttpClientModule } from "@angular/common/http";@NgModule({ imports: [ HttpClientM原创 2021-03-13 22:02:09 · 1406 阅读 · 0 评论 -
angular的父子组件通信
文章目录通信:父传子:{Input}通信:子传父 :(通过事件)双向数据绑定:[(ngModel)]的使用通信:父传子:{Input}//父 <app-child [num]="count"></app-child>// 子html<h1>我是父传过来的:{{num}}</h1>// 子tsimport { Input } from '@angular/core'; @Input() num:any;// 使用别名: @Input('num原创 2021-03-13 14:09:10 · 505 阅读 · 0 评论 -
angular管道多种用法
angular管道多种用法管道参数化// ts文件public birstday = new Date()private flag:boolean = false; get format(){ return this.flag ? "yyyy-MM-dd" : "yyyy/MM/dd" }// html文件{{birstday | date }}{{birstday | date:'yyyy-MM-dd'}}<!-- 管道参数化 -->{{birstday原创 2021-03-13 11:28:20 · 587 阅读 · 0 评论 -
angular响应式表单使用
angular响应式表单使用ReactiveFormsModule引入文件到模块: {ReactiveFormsModule }这里导入文件为:app.module.tsimport { ReactiveFormsModule } from '@angular/forms'declarations: [ AppHighlightDirective ],html<form [formGroup]="myGroup" (ngSubmit)="onSubmit(原创 2021-03-12 00:37:25 · 151 阅读 · 0 评论 -
angular自定义指令Directive使用方法
angular自定义指令Directive1.第一种Directive不传参数1.创建Directive ts文件:highlight.directive.component.tsDirective,ElementRef 引用2个属性import { Directive,ElementRef} from '@angular/core'@Directive({ selector:'[appHighlight]' // []设置为属性 .appHighlight设置为类})exp原创 2021-03-11 22:50:55 · 1450 阅读 · 0 评论