angular2-template

Versioning an Angular 2 App

自闭症网瘾萝莉.ら 提交于 2019-12-03 18:59:43
How can one mark versions of an Angular 2 app? There are some problems like views (via templateUrl ) are not getting updated in route views (child components). I've tried things like <script> System.config({ // baseURL: '/', packages: { app: { format: 'register', defaultExtension: 'js' } } }); System.import('v1/app/boot') .then(null, console.error.bind(console)); </script> Or app/v1/boot and playing with base but it's not working. Note: Just for the record, at development time, cached templates (introduces via templateUrl ) do annoyingly slow things. One should use incognito sessions or clear

ngClass in host property of component decorator does not work

耗尽温柔 提交于 2019-12-03 16:49:37
问题 I created the following simple example component that adds some attributes and listener to the component DOM element using the host property of the @Component decorator. In my case [ngClass] is has no effect. Does someone know why and how to fix it? import {Injector, Component} from "angular2/core"; import {NgClass} from "angular2/common"; import {SelectionService} from "../selection-service" @Component({ selector: 'my-component', template: `<div>inner template</div>`, host: { 'style':

Why does this method/gettor get called X times in an Angular 2 service

时光总嘲笑我的痴心妄想 提交于 2019-12-03 14:39:15
I am trying to bind a value in my HTML component to a property in a service. If the private variable is null then it needs to go off and get the value from an HTTP call. However, I noticed that as soon as I bind to the property gettor in my HTML component then it fires multiple times. I have simplified the example with: this Plunker get Item(): string { console.log("Item()", this._item); return this._item; } Open the Console and observe the multiple outputs of "Item() Initiated". I would expect it to only be hit once. (the result is the same with a method instead of a gettor). If I use the

How to implement ngModel on custom elements?

谁说胖子不能爱 提交于 2019-12-03 14:19:37
问题 Given a simple input element I can do this: <input [(ngModel)]="name" /> {{ name }} This doesn't work for my custom elements: <my-selfmade-combobox [(ngModel)]="name" values="getValues()" required></my-selfmade-combobox> How can I implement it? 回答1: I think this link will answer your question: Angular 2 custom form input We need to implement two things to achieve that: A component that provides the logic of your form component. It doesn't need an input since that will be provided by ngModel

Dynamically bind model and template to at DOM node in Angular 2

若如初见. 提交于 2019-12-03 13:58:43
Short version This Plunker defines a <view> component which can render an arbitrary model+template. This needs to be changed to replace the previously rendered contents rather than appending new peers. EDIT: This is working now, thanks to the response by user3636086. One problem still remains: unlike Angular 1, Angular 2 forces me to create a nested component to update a template (since templates are effectively a static property of a component's class ), so I have a bunch of unnecessary DOM nodes being added. Long Version Angular 1 In our project we'd prefer most of our code to have no direct

How to use template in <p-datatable>

拈花ヽ惹草 提交于 2019-12-03 13:04:14
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" selectionMode="single" sortField="Status" [sortOrder]="-1"> <p-column field="FileName" header="Naam"

Angular2 - recursive html without making a new component?

筅森魡賤 提交于 2019-12-03 12:42:47
问题 In angular 1 I was able to do something like: <script type="text/ng-template" id="commentView.html"> <div> <div style="float: left; position: absolute;" ng-style="comment.displayPercent"> </div> </script> <script type="text/ng-template" id="commentReplies.html"> <div> <div class="commentChildBoxStyle" ng-hide="comment.hideComment"> <div style="min-width: 250px;"> <div ng-repeat="comment in comment.replies" ng-include="'commentReplies.html'"></div> </div> </div> </div> </script> I realize I

How can I pass an array as Input() from the component template?

a 夏天 提交于 2019-12-03 10:29:41
问题 I need to pass an array of values to a component using binding, e.g. @Component({ selector: 'my-component', template: '<div data="[1, 2, 'test']"></div> }) export class MyComponent { @Input() data: any[]; ... } However, it seems Angular treats this as string / string[1] (in the actual project the array is a route and I need to pass this route on to a component which has the [routerLink] directive). How do I go about this? 回答1: You need to wrap the property with [] otherwise it is not

Call a component method from HTML in Angular2

烈酒焚心 提交于 2019-12-03 10:19:06
Is it possible to call a component method from HTML, or should I create another component to handle formatting? <div *ngFor="let item of items"> <div class="title">{{ item.Title }}</div> <p> callComponentMethodHere({{item}}) </p> </div> {{callComponentMethodHere(item)}} but you should avoid that because the method will be called every time change detection runs. It's better to call the method in code (for example in the constructor() , ngOnInit() , or an event handler, assign the result to a property and from the view bind to that property instead. Calling event handlers is fine of course:

Angular 2 unit testing - @ViewChild is undefined

浪尽此生 提交于 2019-12-03 09:22:41
I am writing an Angular 2 unit test. I have a @ViewChild subcomponent that I need to recognize after the component initializes. In this case it's a Timepicker component from the ng2-bootstrap library, though the specifics shouldn't matter. After I detectChanges() the subcomponent instance is still undefined. Pseudo-code: @Component({ template: ` <form> <timepicker #timepickerChild [(ngModel)]="myDate"> </timepicker> </form> ` }) export class ExampleComponent implements OnInit { @ViewChild('timepickerChild') timepickerChild: TimepickerComponent; public myDate = new Date(); } // Spec describe(