angular2-template

Is it possible to add a dynamic class to host in Angular 2?

和自甴很熟 提交于 2019-12-20 17:48:08
问题 I know that in Angular2 I can add a class 'red' to a component's selector element by doing this: @Component({ selector: 'selector-el', host: { '[class.red]': 'true' }, ... }) I'm wondering whether there's a way to add a dynamic class to a host, similar to what you would do with NgClass (I know NgClass is not actually supported, I'm looking for possible solutions): @Component({ selector: 'selector-el', host: { '[NgClass]': 'colorClass' }, ... }) ... constructor(){ this.colorClass = 'red'; }

Please add a @Pipe/@Directive/@Component annotation. Error

99封情书 提交于 2019-12-20 16:24:45
问题 I am stuck in a situation here. I am getting an error like this. compiler.es5.js:1694 Uncaught Error: Unexpected value 'LoginComponent' declared by the module 'AppModule'. Please add a @Pipe/@Directive/@Component annotation. at syntaxError (compiler.es5.js:1694) at compiler.es5.js:15595 at Array.forEach (<anonymous>) at CompileMetadataResolver.webpackJsonp.../../../compiler/@angular/compiler.es5.js.CompileMetadataResolver.getNgModuleMetadata (compiler.es5.js:15577) at JitCompiler.webpackJsonp

Angular 2 different views based on Desktop or Mobile

非 Y 不嫁゛ 提交于 2019-12-20 10:13:29
问题 I'm working on web site, that has slight different functionality based on version desktop/mobile. I tried to apply it via @View, but it looks like this decorator is now deprecated. Please, advise me best practice, how to implement this feature in Angular 2. 回答1: The ng2-responsive package should cover your needs: https://www.npmjs.com/package/ng2-responsive I haven't used it extensively yet, but it seems to be doing a decent job. @View was merged into @Component (ages ago). @Component should

Type checking in Angular 2 templates

◇◆丶佛笑我妖孽 提交于 2019-12-20 09:56:31
问题 We are building an application in Angular 2 and TypeScript. We try to statically check types where it is possible. Is there any way to check types in templates? Consider the following fragment: <foo [data]="dataObj"></foo> Assume that data in Foo component has some type TData . However, by default, nothing prevents me from passing dataObj that does not conform to TData . Is there a typescript extension for Angular templates that would verify the types in such a case? 回答1: Unfortunately, It

Angular 4: Update template variable after API call [duplicate]

怎甘沉沦 提交于 2019-12-20 04:45:12
问题 This question already has answers here : Angular 2 View will not update after variable change in subscribe (4 answers) Closed last year . I have a Component-directive that I use to show a div with some information. This component is called SitesComponent and is included in a page. The main behavior of the SitesComponent is fine, except for this: I have an API call to a backend where I return some data, the backend call is executed well and I received the information but the variable is not

Delay navigating to next page

痴心易碎 提交于 2019-12-20 02:13:57
问题 My angular site works great, but when you click into a project it loads the page, right away and sometimes there is a flash while the images are pulled from the API , id like a 1 second delay, or page transition effect. but i'm not sure how to implement this in Angular 2. Interested to hear what others are doing ? Thanks in advance 回答1: You can implement CanDeactivate interface, something like this: routerCanDeactivate(currTree?: RouteTree, futureTree?: RouteTree): Promise <boolean> { return

Sibling event communication in Angular 2

谁都会走 提交于 2019-12-19 10:15:27
问题 I have five components in my project at the time which are 1: AppComponent (Main component) 2: AuthComponent 3: HomeComponent 4: HeaderComponent 5: FooterComponent Html for "AppComponent" is <section class="app content-area"> <ng2-slim-loading-bar [height]="'4px'"></ng2-slim-loading-bar> <fds-header *ngIf="_appDataService.isLoggedIn"></fds-header> <router-outlet></router-outlet> <fds-footer></fds-footer> Now "HomeComponent" and "AuthComponent" is rendering in "router-outlet" and

How to iterate form array(array in array in array) in angular2 reactive forms?

。_饼干妹妹 提交于 2019-12-19 09:40:22
问题 I tried to Iterate formArray several times, This is plunker link for this case https://plnkr.co/edit/4kiJF7cL5VKwn3KnvjvK?p=preview i want out put like this plunk https://plnkr.co/edit/zg6nbFULl0WlTZ1sVn5h?p=preview This is my scenario [ { "id": 1, "legend": "businessModule", "group": [ { "id": 1, "permission": { "controleType": "ff", "id": 2, "key": "create Business" }, "roles": [ { "id": 1, "name": "self" }, { "id": 2, "name": "other" } ] }, { "id": 1, "permission": { "controleType": "ff",

Angular Create Style Tag in View Template?

我与影子孤独终老i 提交于 2019-12-19 07:35:14
问题 I want to create a generic html fragment component. The idea being we may store html fragments in a db somewhere, and styles that should be applied to them. I can easily set the innerHtml to insert the html structure into a base element in my view template, but how do i dynamically insert a <style> tag in my view template? Here's what I have: @Component({ moduleId: module.id, selector: 'htmlFragment', styleUrls: ['html-fragment.css'], templateUrl:'html-fragment.html' }) export class

Angular 2 error- There is no directive with “exportAs” set to “ngModel” with RC4 version

余生长醉 提交于 2019-12-19 06:17:27
问题 I am using angular 2 forms in my application and i have created the forms based on given link. https://angular.io/docs/ts/latest/guide/forms.html In this for validation and to use forms APIs, i have set the ngModel values like #name="id" #id="ngModel" and which throws script error. But its resolved if i set #id="ngModel" as #id="ngForm" . But for my case i have to set my model value to ngModel . Below is my html page. <form (ngSubmit)="onSubmit()" #myForm="ngForm"> <div class="form-group">