angular2-template

Angular reusable template

本秂侑毒 提交于 2019-12-04 12:24:51
问题 Is it possible to write reusable ng-template ? A lot of my components use exactly the same ng-template . For example: <kendo-grid> <kendo-grid-column field="group"> <ng-template kendoGridEditTemplate let-dataItem="dataItem" let-formGroup="form"> <kendo-dropdownlist #listGroups [data]="groups" textField="title" valueField="id" [valuePrimitive]="true" [filterable]="true" [formControl]="form.get('groupId')"> </kendo-dropdownlist> </ng-template> </kendo-grid-column> </kendo-grid> I do not want to

Angular 2: A property set during OnInit is undefined on the template

断了今生、忘了曾经 提交于 2019-12-04 12:15:39
I have this component: export class CategoryDetailComponent implements OnInit{ category: Category; categoryProducts: Product[]; errorMessage: string; constructor(private _categoryService: CategoryService, private _productService: ProductService, private _routeParams: RouteParams ) {} ngOnInit() { this.getCategoryAndProducts(); } getCategoryAndProducts() { let categoryName = this._routeParams.get('name'); let categoryId = this.routeParams.get('id'); var params = new URLSearchParams(); params.set('category', categoryName); Observable.forkJoin( this._categoryService.getCategory(categoryId), this.

Angular 2 RC6 - “sidebar” is not a known element

北慕城南 提交于 2019-12-04 10:08:12
I just updated to RC6 and have trouble with the following error: zone.min.js:1 Unhandled Promise rejection: Template parse errors: 'sidebar' is not a known element: 1. If 'sidebar' is an Angular component, then verify that it is part of this module. 2. If 'sidebar' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schema' of this component to suppress this message. (" sidebar isn't a component. Just a html-tag i am using in one of my templates. They look like this: ... <sidebar class="main-nav"> ... </sidebar> ... I tried updating my NgModule AppModule with CUSTOM_ELEMENTS

Angular2, TypeScript, How to read/bind attribute value to component class (undefined in ngOnInit) [duplicate]

末鹿安然 提交于 2019-12-04 10:07:13
问题 This question already has answers here : Angular 2 external inputs (4 answers) Closed 3 years ago . can someone please advice me how to read/bind attribute value to @component class, which seems to be undefined in ngOnInit method? Here's a plunker demo: http://plnkr.co/edit/4FoFNBFsOEvvOkyfn0lw?p=preview I'd like to read value of "someattribute" attribute <my-app [someattribute]="'somevalue'"> inside the App class (src/app.ts) ngOninit method. Thanks! 回答1: You can notice that such parameters

Angular 2 prevent click on parent when clicked on child

限于喜欢 提交于 2019-12-04 09:54:40
问题 I have a click event nested one level. When i click on the child the expected function is called but the parent's function is also called. Here is the code <li class="task-item" *ngFor="let task of tasks" (click)="showTask(task.name)"> <input type="checkbox" [ngModel]="task.taskStatus" (ngModelChange)="changeTaskStatus($event)" /> </li> So when the checkbox changes changeTaskStatus() and the showTask() called together. I want the parent to keep quiet when checkbox changes. How do I achieve

What is the difference between ngAfterContentInit and ngAfterViewInit?

我们两清 提交于 2019-12-04 09:13:09
问题 What is the difference between functions ngAfterContentInit and ngAfterViewInit ? 回答1: Content is what is passed as children usually to be projected at some <ng-content> element of a component. View is the template of the current component. The view is initialized after the content and ngAfterViewInit() is therefore called after ngAfterContentInit() . @Component({ selector: 'parent-cmp', template: '<div #wrapper><ng-content></ng-content></div>' }) class ParentComponent { @ViewChild('wrapper')

Access template reference variables from component class

痞子三分冷 提交于 2019-12-04 07:28:53
问题 <div> <input #ipt type="text"/> </div> Is it possible to access the template access variable from the component class? i.e., can I access it here, class XComponent{ somefunction(){ //Can I access #ipt here? } } 回答1: That is a use-case for @ViewChild : https://angular.io/docs/ts/latest/api/core/index/ViewChild-decorator.html class XComponent{ @ViewChild('ipt') input: ElementRef; ngAfterViewInit(){ // this.input is NOW valid !! } somefunction(){ this.input.nativeElement...... } } Here's a

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

本秂侑毒 提交于 2019-12-04 07:25:44
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:13324collection_1.StringMapWrapper.merge.onError @ angular2.dev.js:13228run @ angular2-polyfills.js:141

How to preload angular2 views so will not flicker white page on first load?

荒凉一梦 提交于 2019-12-04 05:53:16
I am building an angular 2 app in plain JS. My problem is that when I change from a page to another it flicker a white page until the new view is rendered. This happens for all components only first time I access them. If I go to same route second time the page is loaded without white page. I capture the screen to explain better my problem: https://drive.google.com/file/d/0B5pOsXT-4rdTbmtuVnlUdXRMdE0/view?usp=sharing Here is my main view: <router-outlet></router-outlet> <nav id="menu"> <a [routerLink]="['Page1']">Page 1</a> <a [routerLink]="['Page2']">Page 2</a> <a [routerLink]="['Page3']"

Calling Angular2SocialLoginModule function calls not supported

孤人 提交于 2019-12-04 04:10:19
问题 I am new to angular js2. Currently I am working with a web application, which uses angular2 for front-end. In this application I have used angular2-social-login for authentication purpose. But when I run the npm start I got the below error ERROR in Error encountered resolving symbol values statically. Calling function 'Angular2SocialLoginModule', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol AppModule in