angular2-template

Angular 2. What is faster to render: [ngClass] or class=“{{}}”?

泄露秘密 提交于 2020-01-24 15:29:47
问题 What will render faster? <div class="ololo" [ngClass]="{'my-class': myVar}">one</div> or <div class="ololo {{myVar ? 'my-class': ''}}">another</div> or some another way? 回答1: I did some research and can surely say that this approach <div class="ololo" [ngClass]="{'my-class': myVar}">one</div> works about 3 times slower than <div class="ololo {{myVar ? 'my-class': ''}}">another</div> please see a demo https://stackblitz.com/edit/angular-fvtzck 来源: https://stackoverflow.com/questions/46605252

How do I integrate trix-editor in an angular 2 app?

大憨熊 提交于 2020-01-24 04:28:08
问题 I am trying to use trix editor for my angular app. However, I am not getting any resources/npm packages to install trix editor in an angular 2 app. Can you help me with the resources/steps to do so? 回答1: I also can not find any for angular2+. Just set it up. angular.json add below "styles": [ "node_modules/trix/dist/trix.css" ], "scripts": [ "node_modules/trix/dist/trix.js" ] attach editor at HTML you want to put it. angular using as selector and trix using as target location of editor. It

Angular 2 dynamically set routerLink using a component property

ε祈祈猫儿з 提交于 2020-01-24 03:45:33
问题 I have created an component that contains a element with a routerLink property which I want to set from a template that uses the component. When I try to do this I get the error message 'Cannot read property 'path' of undefined'. My component looks link this: info-box.component.ts import { Input, Component } from "@angular/core"; import { ROUTER_DIRECTIVES } from "@angular/router"; @Component({ selector: "info-box", template: require("./info-box.component.html"), directives: [ ROUTER

Dynamic ngTemplateOutlet value

霸气de小男生 提交于 2020-01-24 03:15:14
问题 Is there a way to dynamically set the value of the *ngTemplateOutlet directive? Something along those lines: <div *ngFor="let item of [ 'div', 'span' ]"> <ng-container *ngTemplateOutlet="{{ item }}"></ng-container> </div> <ng-template #div> <div>some text inside a div</div> </ng-template> <ng-template #span> <span>some text inside a span</span> </ng-template> Of course it doesn't work but I guess it explains quite well what I'm trying to achieve: if the item is "div", then it should display

Dynamic ngTemplateOutlet value

半世苍凉 提交于 2020-01-24 03:15:08
问题 Is there a way to dynamically set the value of the *ngTemplateOutlet directive? Something along those lines: <div *ngFor="let item of [ 'div', 'span' ]"> <ng-container *ngTemplateOutlet="{{ item }}"></ng-container> </div> <ng-template #div> <div>some text inside a div</div> </ng-template> <ng-template #span> <span>some text inside a span</span> </ng-template> Of course it doesn't work but I guess it explains quite well what I'm trying to achieve: if the item is "div", then it should display

Angular 2 RC6 - “sidebar” is not a known element

≯℡__Kan透↙ 提交于 2020-01-23 00:58:11
问题 I just updated to RC6 and have trouble with the following error: zone.min.js:1 Unhandled Promise rejection: Template parse errors: 'sidebar' is not a known element: 1. If 'sidebar' is an Angular component, then verify that it is part of this module. 2. If 'sidebar' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schema' of this component to suppress this message. (" sidebar isn't a component. Just a html-tag i am using in one of my templates. They look like this: ...

Angular 2 material : sidenav toggle from component

拥有回忆 提交于 2020-01-22 07:08:07
问题 I'm using Angular 2 Material sidenav in my project this way: <md-sidenav-layout> <md-sidenav #start mode="side" [opened]="true"> <md-nav-list> </md-nav-list> </md-sidenav> <button md-button (click)="start.toggle()">Close</button> <router-outlet></router-outlet> </md-sidenav-layout> How to call start.toggle() from my component instead of element with click event? Thank you for reading 回答1: You want to declare a ViewChild in your controller that references the MdSidenav inside your component,

Click event in ng2-dragula bag not working

人盡茶涼 提交于 2020-01-17 08:02:52
问题 I'm using Angular 2 and ng2-dragula . I want to make the drag 'n' drop items in a dragula bag clickable. This is my app.component.html : <div id="rootFrame"> <div class="tasksFrame"> <div id="tasksCont" class='container' [dragula]='"first-bag"'> <div (click)="onClick('ha')">Task 1</div> <div (click)="onClick('ba')">Task 2</div> <div (click)="onClick('ca')">Task 3</div> </div> </div> <div class="editorFrame"> <div id="editorCont" class='container' [dragula]='"first-bag"'> </div> </div> <div

Angular2: Displaying components in row/column fashion

情到浓时终转凉″ 提交于 2020-01-17 08:01:33
问题 I have an array with the below structure where the first field is the component name, second is the data for that component, third is column number and fourth is row number. I am planning to display these items based on their col and row location. [ {"PieChart", Piechartdata, 0,1}, {"donut", donutdata, 1,0}, {"grid", griddata, 1,1} ] I tried to use *ngFor and loop through these array and use switch case to call the desired component. But all these components are displayed one below the other.

Angular2: Displaying components in row/column fashion

百般思念 提交于 2020-01-17 08:01:13
问题 I have an array with the below structure where the first field is the component name, second is the data for that component, third is column number and fourth is row number. I am planning to display these items based on their col and row location. [ {"PieChart", Piechartdata, 0,1}, {"donut", donutdata, 1,0}, {"grid", griddata, 1,1} ] I tried to use *ngFor and loop through these array and use switch case to call the desired component. But all these components are displayed one below the other.