angular2-template

Angular 2 - background image into a html file using ngStyle

为君一笑 提交于 2019-12-06 04:52:44
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 }} + ')'}"> You don't need use {{}} for call some propiety than you put in a directive, like this: import

Angular4 template reference variable assignment

被刻印的时光 ゝ 提交于 2019-12-06 03:10:34
I've come across this example where we can see: <md-menu #menu="mdMenu"> I can't find any reference to the ="mdMenu" part of this template in the docs . Is there some meaning to this or is it just a mistake on the example? In the doc [mdMenuTriggerFor]="menu" refers to <md-menu #menu="mdMenu"> and in #menu="mdMenu" , mdMenu is the directive exported from Material. 来源: https://stackoverflow.com/questions/46581046/angular4-template-reference-variable-assignment

Retain data on page reload in Angular 2

a 夏天 提交于 2019-12-06 03:08:16
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. Smit 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 choose the below. LocalStorage Cookie Session Difference and importance: How to store token in Local or

How to access Child Component HTML Element values in Parent Component in angular2?

﹥>﹥吖頭↗ 提交于 2019-12-06 02:56:26
I have used below code to access child component HTML element values in parent component during parent component's button click. Child Component.ts:- @Component({ selector: 'child-component', template: `<md-input-container><label>Title</label><input [(ngModel)]="Title" #Title></md-input-container><md-input-container><label>Name</label><input [(ngModel)]="name" #Name></md-input-container><md-input-container class="md-block" flex-gt-sm><label>State</label><md-select [(ngModel)]="user.state" #State><md-option *ngFor="let state in states" value="{{state.abbrev}}">{{state.abbrev}}</md-option></md

Cannot read property 'filter' of null in angular 2?

谁说我不能喝 提交于 2019-12-06 00:36:43
问题 I am getting this error Cannot read property 'filter' of null when I apply filter in angular 2 .here is my code http://plnkr.co/edit/K46jJsnmHiONuqIsnuzW?p=preview import {Pipe} from 'angular2/core'; @Pipe({ name: 'sortByName', pure: false, }) export class SortByNamePipe { transform (value, [queryString]) { // console.log(value, queryString); return value.filter((student)=>new RegExp(queryString).test(student.name)) // return value; } } 回答1: It's because you have data as input that are loaded

Angular 2 + Semantic UI , component encapsulation breaks style

血红的双手。 提交于 2019-12-05 21:58:37
问题 I'm using Angular2 with Semantic UI as a css library. I have this piece of code: <div class="ui three stakable cards"> <a class="ui card"> ... </a> <a class="ui card"> ... </a> <a class="ui card"> ... </a> </div> the cards are rendered nicely with a space between and such. like this: refer to cards section in the link since the cards represent some kind of view I thought of making a component out of it, so now the code is: <div class="ui three stakable cards"> <my-card-component></my-card

How to save model manipulation of *ngFor with pipes? - “#item of (result = (items | orderAsc))” doesn't work in A2

a 夏天 提交于 2019-12-05 20:07:27
So I populate a table with *ngFor and use pipes to filter and order the given items array. This works perfectly and the table rows are created as expected. But I also wan't to use the result of the pipes in my component hosting the table. How can this be achieved with angular2? my current html: <tr *ngFor="#item of items | orderAsc">{{item.name}}</tr> the old angularJS way of saving the result: <tr *ngFor="#item of (result = (items | orderAsc))">{{item.name}}</tr> where "result" could be used in the corresponding controller. What is the angular2 way of achieving this? I'd like to keep the

convert string to number angular 2 one way binding

故事扮演 提交于 2019-12-05 20:03:08
convert the string to number angular 2 one way binding [longitude]="loc.location.lng"> loc.location.lng is string i need to convert them to number.but still not working as I expect. In interpolation it's working but in this not working. Thanks Make a function which convert the value to float as its location and return the value. ConvertString(value){ return parseFloat(value) } Call the function in template [longitude]="ConvertString(loc.location.lng)" You could also force the cast by trying this: [longitude]="+loc.location.lng" Since you havent provided your source code, its difficult to help

Angular2 - Template reference inside NgSwitch

时间秒杀一切 提交于 2019-12-05 19:00:32
I have a NgSwitch template. In the NgSwitch I want to get a template reference to the initialized template. Something like this: <div class="container" [ngSwitch]="model.type"> <first-component #ref *ngSwitchCase="0"></first-component> <second-component #ref *ngSwitchCase="1"></second-component> <third-component #ref *ngSwitchCase="2"></third-component> </div> When clicking on a button in the component I want to call to the initialized component (first/second/third) to a method (which defined on an interface that all these 3 component implement). The problem is the ViewChild is undefined. If I

Good template strategy for authentication in Angular 2

怎甘沉沦 提交于 2019-12-05 18:16:31
问题 I currently have an Angular 2 app up and running that looks as follows: App.component is bootstrapped when visiting the site. The template for App.component has all component tags (for example menu.component, search.component and the router-outlet). What I basically need is the following: currently a visitor is directly redirected to the Login page because the user needs to login. He is still able to see the menu and all components that are only there for logged in users. What would be the