angular2-template

Angular 2 - background image into a html file using ngStyle

自作多情 提交于 2019-12-22 11:57:50
问题 I am pulling data from an API using an Angular 2 service.. I can output everything from the json api onto the page using something similar to this {{ project.title }} however i wish to output the url to a background image and I cant seem to get it working.. has anyone got any ideas or advice ? Currently this is what I have. I've tried it without the curly braces also but nothing is working. <div class="table-wrap featuredimg" [ngStyle]="{'background-image': 'url(' + {{ project.projectimage }}

Retain data on page reload in Angular 2

懵懂的女人 提交于 2019-12-22 09:49:09
问题 In my Angular 2 app, I pass in some data to a PageComponent from my HomeComponent which is then saved to a variable inside the PageComponent. Now when I refresh the page I need this data to be retained. Currently I am using session storage, but I was wondering if there is a better way to implement this. 回答1: Nope, There isn't a other way in this context. Once you refresh all the temporary memory is gone. As you said you are performing session-storage. You may continue with that. You may

ViewChild and focus()

心不动则不痛 提交于 2019-12-22 09:17:42
问题 I have a component which contains a textarea which is hidden by default : <div class="action ui-g-2" (click)="toggleEditable()">edit</div> <textarea [hidden]="!whyModel.inEdition" #myname id="textBox_{{whyModel.id}}" pInputTextarea focus="true" [(ngModel)]="whyModel.description"></textarea> When I click on the "edit" div I want to show the textarea and put focus on it : @ViewChild('myname') input: ElementRef; ... private toggleEditable(): void { this.whyModel.toggleEditable(); this.input

Bind Select List with FormBuilder Angular 2

余生长醉 提交于 2019-12-22 08:41:10
问题 In Angular 2, creating a simple app but when formBuilder is attached with DOM control in case of select list , First option is coming blank - even if I provided some initial value in formBuilder that value is not coming to DOM element Before FomBuilder Select List Genral LDAP After FomBuilder Select List No option appearing initially Genral LDAP File 1 - form.component.ts import { Component } from '@angular/core'; import { FormBuilder, Validators, REACTIVE_FORM_DIRECTIVES, FormGroup,

What's the difference between ref- prefix and # in Template reference variable (Angular 2)

亡梦爱人 提交于 2019-12-22 08:40:12
问题 I want to understand the difference between template reference variable notations as mentioned below in the input text boxes. <input type="text" name='name' #name [(ngModel)]='model'> <input type="text" name='name' ref-name [(ngModel)]='model'> What's the difference between using #name and ref-name . Does the scope of the variable changes on using ref-name ? Can anybody please suggest the best practice and reason ? 回答1: They are two different syntaxes for literally exactly the same thing. You

How can I use NgFor without creating arrays to generate matrix UI pattern

↘锁芯ラ 提交于 2019-12-22 06:24:54
问题 I would like to implement UI matrix pattern, which should generate dynamically. By receiving input parameter it should decide what would be UI matrix pattern dimensions: For example 9X3 elements: pattern 9x3 elements I use Angular2.js, typescript, SCSS. html tamplate and .ts looks: import {Component, Input, OnInit} from 'angular2/core'; import {NgFor} from 'angular2/common'; @Component({ selector : 'game-pattern', moduleId : module.id, templateUrl: 'game-pattern.component.html', styleUrls : [

Should Angular2 @Inputs be public or can/should we have a stricter API by making them private?

前提是你 提交于 2019-12-22 04:14:11
问题 I am using Angular2 with Typescript Suppose I have the following in my app component's template: ... <coffee-cup [coffee]="" ... My coffee-cup component: @Component({ selector: 'coffee-cup', ... }) export class CoffeeCup { @Input() public coffee = 0; } I am currently unsure of what my Input should look like. It could look like this: @Input() public coffee = 0; Or @Input() private coffee = 0; I am currently leaning towards making the member variable coffee private. I want to define a clear

Angular2 Component inside ngFor throws Error (viewFactory is not a function)

廉价感情. 提交于 2019-12-21 14:12:03
问题 I have a a ComponentB in a Angular 2 app (beta 1). It works perfectly fine until I place it inside a ngFor loop in ComponentA. I receive the rather cryptic error of: EXCEPTION: TypeError: viewFactory_ComponentB0 is not a function in [numbers in ComponentA@1:23]BrowserDomAdapter.logError @ angular2.dev.js:22690BrowserDomAdapter.logGroup @ angular2.dev.js:22701ExceptionHandler.call @ angular2.dev.js:1163(anonymous function) @ angular2.dev.js:12416NgZone._notifyOnError @ angular2.dev.js

how do I fire onload events for elements within component html in angular2

北战南征 提交于 2019-12-21 10:54:07
问题 So this is a 2 in 1 question. First, I am trying to fire a function when an element, within a components html, loads. I tried it numerous ways, like: <div [onload]="myFunction()"> this however results in the function being called multiple times, 10 to be exact. My guess is this is not the way to go, but I am not familiar enough to get it working properly. Also I would like to send the element along as a parameter. For example doing <div #myDiv (click)="myFunction(myDiv)"> does work, but

How to use template in <p-datatable>

狂风中的少年 提交于 2019-12-21 04:19:20
问题 I've got a very basic question which I can't answer myself because most links to http://www.primefaces.org/primeng don't work anymore. I also tried registering to their forum but their activation mail never arrives. I use Angular2 and have a datatable with two columns: filename and status. The status column I want to change. It holds now a number from 1 to 4 and I want to show a glyphicon based on the status. I now have this, which is working: <p-dataTable [hidden]="loading" [value]="files"