angular2-template

Can't bind to '*ngIf' since it isn't a known property of 'td' in angular2

吃可爱长大的小学妹 提交于 2021-02-08 06:44:24
问题 in my angular 2 application In ts file i have below click even, ViewPages(Char: string): void { this.selectedPage = Char; } In html, i tried to bind select page in ngif <td *ngIf="name[0] == {{selectedPage}}">{{name}}</td> but it is throwing the ""Can't bind to '*ngIf' since it isn't a known property of 'td'. it will be grt help if someone help me regarding this 回答1: You should use ng-container for this. It isn't added to resulting html. <ng-container *ngIf="name[0] == {{selectedPage}}"> <td>

ViewChildren doesn't bind in ngFor

早过忘川 提交于 2021-02-07 13:15:01
问题 I have a simple template: <div *ngFor="let skill of allSkills | async "> <div class="skill-chart-with-img"> <skill-chart-view></skill-chart-view> <div #skillImg> some data </div> </div> </div> When I try to bind on #skillImg, I have an empty QueryList: @ViewChildren("skillImg") private skillImgs: QueryList<ElementRef>; ngAfterViewInit(): void { this.skillImgs.forEach((skill: ElementRef) => { //some work with skill }); } Maybe I miss something or my task have a better solution? 回答1: The

ViewChildren doesn't bind in ngFor

妖精的绣舞 提交于 2021-02-07 13:05:03
问题 I have a simple template: <div *ngFor="let skill of allSkills | async "> <div class="skill-chart-with-img"> <skill-chart-view></skill-chart-view> <div #skillImg> some data </div> </div> </div> When I try to bind on #skillImg, I have an empty QueryList: @ViewChildren("skillImg") private skillImgs: QueryList<ElementRef>; ngAfterViewInit(): void { this.skillImgs.forEach((skill: ElementRef) => { //some work with skill }); } Maybe I miss something or my task have a better solution? 回答1: The

Remove objects from array in typescript

点点圈 提交于 2021-02-07 08:55:37
问题 how do i remove object from an array in typescript? "revenues":[ { "drug_id":"20", "quantity":10 }, { "drug_id":"30", "quantity":1 }] so i want to remove the drug_id from all objects. how do i achieve that? Thank You! 回答1: you could use that : this.revenues = this.revenues.map(r => ({quantity: r.quantity})); For a more generic way of doing this : removePropertiesFromRevenues(...props: string[]) { this.revenues = this.revenues.map(r => { const obj = {}; for (let prop in r) { if (!props

Strip html in Angular template binding

旧时模样 提交于 2021-02-06 09:19:10
问题 I have a list displaying data that can sometimes contain HTML <li *ngFor="let result of results"> <span [innerHTML]="result.question.title"> </span> </li> The problem with using innerHTML is that the HTML gets parsed and rendered, so things like <p> tags will add margins and ruin the list's alignment. I would like to strip all html tags and just output plain text. An approach like this: <li *ngFor="let result of results"> <span> {{result.question.title}} </span> </li> does not strip the HTML,

Angular: Template Driven Forms - Enable submit button if at least one field is entered

爷,独闯天下 提交于 2021-01-28 06:12:26
问题 I have a simple form that has a set of fields and I want to enable the submit button if at least one field has been entered. I don't wanna use a Model Driven Form as I feel it's a overkill, given the scenario. What is the simplest way to check if at least one field is not empty in Template Driven Forms? 回答1: You can work with ngModel and ngModelChange . In your html: <input type="text" class="form-control" [(ngModel)]="yourvalue" (ngModelChange)="valueChanged()" /> In your component: private

Angular2 - Keyup require a clarification

拜拜、爱过 提交于 2021-01-27 08:15:48
问题 In my app, conditionally i am adding a class. and when the user enter something i am checking the value and accordingly i am adding the class name. it works fine. but it only updates on set of (keyup)='0' - setting some value on keyup . this is not like angular 1 here. so any one explain me why do we set the (keyup)=0 here? and what it do for us? here is my code : import {Component} from "angular2/core" @Component({ selector : 'my-component', template : ` <h2>My Name is: {{name}} <span [class

Angular component default style css display block

荒凉一梦 提交于 2021-01-26 03:13:19
问题 I am sick of all my angular elements being 0x0 pixels, because they have names like app-card, app-accordion, which the browser does not recognise as HTML5 compliant elements and as thus, will not give any default styles to. This is means that inspecting it in Chrome, I fail to see the container dimensions and when the DOM is really deep, it is hard to understand which element encompasses which area on the screen, etc. It feels logical to me that all angular elements should be block displayed

How to bind JSON object key value pair separately to angular template

喜欢而已 提交于 2021-01-24 14:02:31
问题 And i have a dynamic json coming from an API as below: {123: "Mumbai", 456: "Bangalore", 789: "Chennai", 101: "Andhra",...} I have below HTML code written in my template in which I am getting image-1, image-2 logos from my assets folder <div class="row"> <div class="col-6" (click)="cityClick('Bangalore')"> <div class="img-1"> // my image-1 logo goes here </div> <div class="img-text"> Bangalore </div> </div> <div class="col-6" col-6 (click)="cityClick('Mumbai')"> <div id="image_block" class=

Angular 2 : increment *ngFor by 2 or implementing two paginations with in a Pagination

筅森魡賤 提交于 2020-12-31 06:41:47
问题 I am pretty new to Angular and I was wondering if there is any way to increment the ngFor loop by 2 instead of 1. I am trying to implement two pagination's with in a pagination for which increment the loop by 2 is required. I am getting objects which have objects with in. Lets say users and list of their address. (First NgFor is to paginate the users by 2. If I get 15 users. 2 users will be displayed in one page) li *ngFor="let user of Users | paginate: { itemsPerPage: 1, currentPage: p };let