After create a component dynamic, we are able to change the component's props and listen to its event. component: ComponentRef<AuthFormComponent>; ngAfterContentInit() { const factory = this.resolver.resolveComponentFactory(AuthFormComponent);this.c…
Let's say you want to rending some component based on condition, for example a Tabs component. Inside tabs, you want to render different tab component: <div *ngFor="let comp of comps"> <ng-container *ngComponentOutlet="comp"&g…
Oingial aritial --> Link Take away: import { Component, OnInit } from '@angular/core'; @Component({ selector : 'contacts-header', templateUrl: './header.component.html', styleUrls : ['./header.component.css'] }) export class HeaderComponent implement…
每天抽出一些时间学习 Angular2 ,并准备把手头上的项目移植为 Angular2 , 不过今天又遇到了一些小问题. 准备写一个导航类适于管理后台常见的右边导航,如博客园的这种: ! 使用 g generate component nav-left 建立了一个名为 nav-left 的导航组件. 这里需要检查app,modile.ts中是否已经有你新建的组件.一般会自动添加,如果不存在需要添加引用: import { NavLeftComponent } from './nav-left/n…
Component: import { Component, Input, ChangeDetectionStrategy, EventEmitter, Output } from '@angular/core'; @Component({ selector: 'stock-counter', changeDetection: ChangeDetectionStrategy.OnPush, template: ` <div class="stock-counter"> &l…
Vue dynamic component All In One Vue 动态组件 vue 2.x https://vuejs.org/v2/guide/components-dynamic-async.html vue 3.x https://v3.vuejs.org/guide/component-dynamic-async.html 动态组件 & 异步组件 <component v-bind:is="currentTabComponent"></comp…
更新 2018-02-07 详细讲一下 TemplateRef 和 ViewContainerRef 的插入 refer : https://segmentfault.com/a/1190000008672478 https://stackoverflow.com/questions/45438304/insert-a-dynamic-component-as-child-of-a-container-in-the-dom-angular2 https://stackoverflow.com/q…
原文:http://davidcai.github.io/blog/posts/router-dynamic-templates/ ui-router : templateProvider vs template ---------------------------------------------- Router: Dynamic Templates Sat Aug 15, 2015 This post discusses how to create dynamic templates b…
export default (ngModule) => { describe('Table Item component', () => { let $compile, directiveElem, directiveCtrl, $scope, state, parentElement; beforeEach(window.module(ngModule.name)); beforeEach(inject(function (_$compile_, _$rootScope_, _$state…
To create a component dynamicly. 1. Add a container with ref: @Component({ selector: 'app-root', template: ` <div> <div #entry> <!-- We want to create auth-form component inside this div--> </div> </div> ` }) 2. View this con…
本文所有内容以 Angular 2 Quick Start 项目为基础,使用 TypeScript 语言. 如上图,最近遇到一个需求,需要在一个刚启动的 Angular 2 项目中使用 snap.svg 操作页面上的 svg 元素做动画. 我粗略的看了下, snap.svg 的实现似乎并没有遵从什么模块规范,就是常见的提供几个全局变量完事.如果真的耿直的在 Component 中去用的话,会在执行 tsc 编译成 js 文件这一过程中报错. 这是因为 TypeScript 编译器并不知道 sna…
Here is the defulat tab header template: <ng-template #defaultTabHeader let-tabs="tabsX"> <ul class="tab-panel-buttons" *ngIf="tabs"> <li [ngClass]="{selected: tab.selected}" (click)="selectTab(t…
I can use <tamplete> syntax and a entry component as a container to create a dynamic component. Notice it will create a empty div as a placeholder in the DOM. If we don't wanner this empty div, we can actually using ng-conainer together with ngTempl…
This lesson shows you how to build a Toggle Button in Angular 2 from scratch. It covers using transclusion in Angular 2, setting up your own two-way binding, and making the button into a reusable component. toggle-button.ts: import {Component, Input,…
导入所需模块: ReactiveFormsModule DynamicFormComponent.html <div [formGroup]="form"> <label [attr.for]="formItem.key">{{formItem.label}}</label> <div [ngSwitch]="formItem.controlType"> <input *ngSwitchCas…
You can dynamically switch between components in a template by using the reserved <component> element and dynamically bind to its is attribute. By using <keep-alive> you can tell Vue to keep the component in memory. In the previous post about…
The way to test router componet needs a little bit setup, first we need to create a "router-stubs.ts". This file is a helper file. // export for convenience. export { ActivatedRoute, Router, RouterLink, RouterOutlet} from '@angular/router'; impo…
One thing that we can do is to add styles directly to HTML elements that live within our component. However, in this lesson we see that style classes added to your template HTML within your component get applied to an inner <div> and not your compon…
Angular has a very robust security model. Dynamically inserted html, style or url values into the DOM open up possibilities for attackers to compromise your site. Thus Angular treats all values as untrusted by default. In this lesson we learn how to…
import {ComponentFixture, TestBed} from '@angular/core/testing'; import {BrowserDynamicTestingModule, platformBrowserDynamicTesting} from '@angular/platform-browser-dynamic/testing'; import {StockCounterComponent} from './stock-counter.component'; Te…
You can dynamically switch between components in a template by using the reserved <component> element and dynamically bind to its is attribute. By using <keep-alive> you can tell Vue to keep the component in memory. Two children components: &l…
1. 组件Component示例 2. Component常用的几个选项 3. Component全部的选项 3.1 继承自@Directive装饰器的选项 3.2 @Component自己特有的选项 4. 自定义component 1. 组件Component示例 组件是由一个装饰器@Component来声明的,继承自@Directive import {Component} from '@angular/core'; @Component({ selector: 'app-root233',…
如果你之前没有深入了解 Angular 依赖注入系统,那你现在可能认为 Angular 程序内的根注入器包含所有合并的服务提供商,每一个组件都有它自己的注入器,延迟加载模块有它自己的注入器. 但是,仅仅知道这些可能还不够呢? 不久前有个叫 Tree-Shakeable Tokens feature 被合并到 master 分支,如果你和我一样充满好奇心,可能也想知道这个 feature 改变了哪些东西. 所以现在去看看,可能有意外收获嗷. 注入器树(Injector Tree) 大多数开发者知道…
组件指令间经常需要沟通 我们知道的方式有 input output service inject viewchild contentchild templateRef template variable 但是哪种情况下用哪种呢 ? 思考 1, input -> input -> input 这种一层层传进去是否是 ok 的 ? <mat-calendar cdkTrapFocus [id]="datepicker.id" [ngClass]="datepic…
When you generate Angular 2 components, you’re still able to access the component instance to set properties and invoke methods from the component class. import {Component, ViewChild, ViewContainerRef, ComponentFactoryResolver, Input} from '@angular/…
You can place content inside of the instance of your component element then manage it inside of the component’s template using ng-content. This process is called reprojection, but you may be more familiar with the term “transclusion”. Home: <div>I a…
refer : https://angular.cn/docs/ts/latest/guide/template-syntax.html https://angular.cn/docs/ts/latest/cookbook/component-communication.html https://angular.cn/docs/ts/latest/guide/displaying-data.html https://angular.cn/docs/ts/latest/guide/user-inp…
更新 : 2018-01-30 ng 的 overlap 在关闭的时候对 backdrop 做了一个 style pointer 目的是让 backdrop 不被 2 次点击, 但是呢,  css pointerEvent 'none' 也有一个穿透的效果,就是说, backdrop 还没完全关上时, 其后面的按钮是可以被点击到的. 这个需要注意,因为可能你并不想这样. 另外一个要说的是, overlap 是可以打开多个的. 通过多个 overlapRef 去自行做管理. 所以请把 overla…
之前自己写的公共组件,都是会先引入,需要调起的时候再通过service控制公共组件状态.值.回调函数什么的.但是有一些场景不适合这种方式,还是动态添加组件更加好.通过写过的一个小组件来总结下. 创建组件 场景:鼠标移动到图标上时,展示解释性的说明文字.那就需要创建一个普通的tooltip组件.如下: <aside class="hover-tip-wrapper"> <span>{{tipText}}</span> </aside> HT…
本文转自:https://www.techiediaries.com/angular-material-dialogs/ In this tutorial, we're going to learn how to use the Angular Material Dialog component to build a custom dialog example. We'll also see common cases to work with the Angular Material Dialo…