angular2-template

angular 2 rc5 template parse error

穿精又带淫゛_ 提交于 2019-12-06 16:26:47
I keep getting this error when I'm trying to create an angular routing link: zone.js:461 Unhandled Promise rejection: Template parse errors: Can't bind to 'routerLink' since it isn't a known property of 'a'. (" </h1> <button (click)="doLogin()">Login</button> <a [ERROR ->][routerLink]="['/createservice']" href="#">Post a Service</a> <router-outlet></router-outlet> "): AppComponent@4:3 ; Zone: <root> ; Task: Promise.then ; Value: BaseExceptionconsoleError @ zone.js:461 zone.js:463 Error: Uncaught (in promise): Template parse errors:(…) This is my code: <a [routerLink]="['/createservice']" href=

Angular2 this.router.navigate fires only once

只谈情不闲聊 提交于 2019-12-06 15:43:47
I have the following tab structure in my page, with it's respective URLs given in braces: Main Tab (/page) / | \ / | \ / | \ / | \ Sub Tab 1 Sub Tab 2 Sub Tab 3 (/page/a) (/page/b) (/page/c) Component @Input() route: string = ''; selectTab(tab) { let route = this.router.url.split('?')[0]; /* Here redirectUrl = "/page/c" */ if (tab.redirectUrl.length > 0) { // console.log(tab.redirectUr); gives /page/c this.router.navigate([tab.redirectUrl]); // This works but reloads the page and is a very bad idea. // window.location.href = tab.redirectUrl; } } Component.html NOTE: The actual code has a

passing multiple arguments or object in (click)

你离开我真会死。 提交于 2019-12-06 14:29:44
Problem is to pass the object or multiple arguments from template to component and use them to add data to API. task.service.ts addTasks(task: Task): Observable<Task>{ let headers = new Headers({'Content-type': 'application/json'}); let options = new RequestOptions({ headers: headers }); return this.http.post(this.tasksUrl, {task}, options) .map(this.extractData) .catch(this.handleError); } task.component.ts addTasks(task){ this.taskService.addTasks(task) .subscribe( task => this.tasks.push(task), error => this.errorMessage = <any> error ); } Template Inputs: <input #todoTime type="text" class

Angular 2.0.0-rc3: partial route matching with routerLinkActive

被刻印的时光 ゝ 提交于 2019-12-06 11:00:55
问题 I'm using routerLinkActive in my primary routing. <a [routerLink]="/user" routerLinkActive="active">Bob</a> When the URL is /user , the active class will be added to the a tag, but under the primary route, I also have a few secondary routes, so when the URL is /user/aa , the active will be removed. I hope that when the URL is either /user/aa or /user/bb , the primary route's class active still exists. What should I do? 回答1: Add [routerLinkActiveOptions]="{ exact: false }" As far as I know

can I use angular2 and Thymeleaf together?

跟風遠走 提交于 2019-12-06 08:31:44
问题 I put the Thymeleaf th: in angular2 templates, but the th: wont compile. Is there any way I can use them together? import {Component, NgModule} from '@angular/core' import {BrowserModule} from '@angular/platform-browser' @Component({ selector: 'my-app', template: ` <table xmlns:th="http://www.w3.org/1999/xhtml"> <tbody> <tr> <th>User Name</th> <th th:each="role : ${roles}"> <div class="row"> <div th:text="${role.type}"></div> </div> </th> </tr> </tbody> </table>`, }) export class App {} 回答1:

Angular 2 Dynamic Page Header and Footer

微笑、不失礼 提交于 2019-12-06 07:59:38
问题 The following is what is included in my app.component.html <lmenu></lmenu> <header></header> <router-outlet></router-outlet> <footer></footer> However my login and register pages are both rendered through this module and they only require the router-outlet. How an dynamically not include the lmenu, header, and footer selectors for the login and register views? Thanks in advance. 回答1: <lmenu *ngIf="isLogin"></lmenu> <header *ngIf="isLogin"></header> <router-outlet></router-outlet> <footer

Passing data from Parent to Child via template

让人想犯罪 __ 提交于 2019-12-06 07:39:52
I have a template user like following: <div class="jumbotron"> <div class="container"> <h2><i class="fa fa-user"></i> {{username}}</h2> <p><i class="fa fa-star"></i> {{reputation}}</p> </div> </div> <app-list user={{username}}"></app-list> My component for app-list looks like: export class ListComponent implements OnInit { @Input() user: string; constructor() { } ngOnInit() { console.log(this.user); } } The username and reputation is correctly shown on the page. However the username value is not passed correctly to the sub component app-list as it only print out an empty string. How can I pass

access local variable within *ngIf

情到浓时终转凉″ 提交于 2019-12-06 06:33:30
I have a primeng (angular 2) dialog with a dropdown. I want to set focus to the dropdown when the dialog shows. The problem appears to be that my div is rendered conditionally. My code: <p-dialog (onShow)="fe.applyFocus()"> <div *ngIf="selectedItem"> <button pButton type="button" (click)="fe.applyFocus()" label="Focus"></button> <p-dropdown #fe id="reason" [options]="reasonSelects" [(ngModel)]="selectedReason" ></p-dropdown> </div> </p-dialog> In this code the button works fine, but the onShow() (outside the *ngIf div) tells me fe is undefined. How can I access the local variable inside the

How do I get Angular 2/4 to update existing DOM nodes instead of deleting+creating them?

江枫思渺然 提交于 2019-12-06 05:42:27
My Angular 4 application has a Component that has a refresh method that pulls-in a large object from my web-service, like so: DTOs/Model types: class NuclearReactorStatus { public reactorName: string; public coolingRods: CoolingRodStatus[]; // array of 1024 elements } class CoolingRodStatus { public rodId : number; public temperature: number; public status : string; } Inside the NuclearReactorDisplayComponent : public reactorStatus: NuclearReactorStatus; refresh(): void { this.http.get<NuclearReactorStatus>() .subscribe( status => { this.reactorStatus = status; }, err => { console.error( err )

Angular: passing data back from dynamic component

折月煮酒 提交于 2019-12-06 05:10:08
Based on an example in the cookbook, I am creating components dynamically like this: private loadComponent(): void { const componentFactory = this.factoryResolver.resolveComponentFactory(MyInputComponent); const viewContainerRef = this.componentHost.viewContainerRef; viewContainerRef.clear(); const componentRef = viewContainerRef.createComponent(componentFactory); (<IComponent>componentRef.instance).data = data; } MyInputComponent's template would look like this: <input type="text" [(ngModel)]="data.inputProp"> I need to update the value of data.inputProp in the parent when the user types in