angular-template

How to handle template errors (and other errors) in angular 2?

白昼怎懂夜的黑 提交于 2020-01-01 05:20:17
问题 When ever there is a template error in angular 2, the entire application fails to work. Shouldn't only the component that had the template that caused the error, fail to work and the rest of the application be working fine? How to handle errors so that the application won't stop being responsive when an error occurs? 回答1: You can use custom ErrorHandler: class MyErrorHandler implements ErrorHandler { handleError(error) { // do something with the exception } } @NgModule({ providers: [{provide:

Use async pipe in ngFor on Observable of Observables (Angular)

北慕城南 提交于 2019-12-30 08:40:52
问题 I have variable defined like this: myVar: Observable<Observable<MyObject>[]> . I am using Angular4 feature to enumerate with async pipe *ngFor="let obsMyObject of (myVar | async)" now I have Observable of MyObject, but I need just MyObject. I could write something like that: <div *ngFor="let obsMyObject of (myVar | async)"> <div *ngIf="let obsMyObject | async; let MyObject"></div> </div> but I can not do this in inner div, because I am setting flex order (which doesn't have any effect on

how to best conditional template show in angular 4

左心房为你撑大大i 提交于 2019-12-30 04:24:06
问题 currently, i am practiced angular 4. when a normal user view this then show public content When A Registered user enter the web page then show edit or some content . how to the best practices show conditionally template Or Some Html Contents Example: <div *ngIf="isUser"> some Content here...... </div> <div *ngIf="!isUser"> some Content here ..... </div> actually, i want to know how to the best. 回答1: In angular 4 you can use if.. else.. structure for html templates You can use it in this way:

Angular pass multiple templates to Component

两盒软妹~` 提交于 2019-12-30 00:38:55
问题 I'm trying to create a component that accepts multiple templates as inputs. This is the example I have: @Component({ selector: 'data-list', styles: [ require('./data-list.component.scss') ], template: ` <ng-template *ngFor="let item of itemsData" ngFor let-item [ngForOf]="[item]" [ngForTemplate]="itemTemplate" ></ng-template> ` }) export class DataListComponent { @Input() itemsData: any[]; @ContentChild(TemplateRef) itemTemplate: TemplateRef<ElementRef>; } As you can see it's a fairly simple

Dynamic tabs with user-click chosen components

只愿长相守 提交于 2019-12-25 04:25:51
问题 I'm trying to setup a tab system that allows for components to register themselves (with a title). The first tab is like an inbox, there's plenty of actions/link items to choose from for the users, and each of these clicks should be able to instantiate a new component, on click. The actions / links comes in from JSON. The instantiated component will then register itself as a new tab. I'm not sure if this is the 'best' approach? So far, the only guides I've seen are for static tabs, which

ngClass doesn't work Angular 5

有些话、适合烂在心里 提交于 2019-12-24 15:04:44
问题 Hello I am user angular 5 and I want to toggle change a Play <-> Pause icon for my soundcloud player. here is my TypeScript followed by my html. I can see in my console that I toggle correctly the playMode but the font awesome icon doesn't change as it is suppose to do. Thanks for the help. import { Ng2DeviceService } from 'ng2-device-detector'; import { Component, OnInit } from '@angular/core'; import { NgClass } from '@angular/common'; import './soundcloud-script.js'; @Component({ selector:

Angular 6 Nested FormGroup Template Validation

一曲冷凌霜 提交于 2019-12-23 19:14:54
问题 My form group structure looks like this (order.component.ts): this.orderForm = this.formBuilder.group({ customer: this.formBuilder.group({ name: ['', Validators.required], phone: ['', Validators.required], email: ['', Validators.required] }), ... }); In the template (order.component.html) I have: <form [formGroup]="orderForm" (ngSubmit)="onSubmit()"> <fieldset formGroupName="customer"> <legend>Customer Information</legend> <label for="name">Full name:</label> <input type="text"

Access template variable in *ngIf

做~自己de王妃 提交于 2019-12-22 04:43:18
问题 I am trying to define a template variable on an element and use its hidden attribute to identify whether the element is actually present in the DOM and then display another element based on that. But if there is a structural directive, template variable does not seem to return a value. <hr class="divider" *ngIf="true" #divi> <div *ngIf="showResendWelcomeEmailButton"> <a *wpHasAnyPermission="[{'something': true}]" #resendEmailBtn> Resend Welcome Email </a> </div> <div class="pull-right"> <a

Conditional duplicate templateref in ng-content with selector

大兔子大兔子 提交于 2019-12-20 04:48:32
问题 I have a component which toggles the component's template based on client device size. Component code is: import {Component} from '@angular/core'; import {BreakpointObserver, Breakpoints} from '@angular/cdk/layout'; @Component({ selector: 'ui-switcher', template: ` <ng-content *ngIf="isSmall" select="mobile"></ng-content> <ng-content *ngIf="!isSmall" select="web"></ng-content> ` }) export class UiSwitcherComponent { public isSmall: boolean; constructor(breakpointObserver: BreakpointObserver)

AngularJS and Rails routing error

两盒软妹~` 提交于 2019-12-18 20:49:58
问题 I am following the tutorial at: https://thinkster.io/angular-rails/ and when I get to the section: Integrating the Front-end with the Asset Pipeline, things break; the site gets stuck in an infinite loop and keeps producing the same error over and over. I've checked and rechecked each step. Could someone please help: Error: Started GET "/home/_home.html" for ::1 at 2015-04-17 11:55:43 -0400 ActionController::RoutingError (No route matches [GET] "/home/_home.html"): actionpack (4.2.0) lib