angular2-template

cant add script file to components html

断了今生、忘了曾经 提交于 2020-06-12 04:05:26
问题 I have had a script file reference in index.html(root); index.html: <script src="page1.js"></script> <script src="assets/sliderfunctions.js"></script> <script src="assets/js/custom.js"></script> no need sliderfunctions.js here, it contains some specific functions about slider so I carry it to slider.component.html file but as you guess it doesnt work as I expected actually it never loaded to browser.. slider.component.ts: import {Component,ViewEncapsulation} from '@angular/core'; @Component({

Access DOM element with template reference variables on component

非 Y 不嫁゛ 提交于 2020-06-08 19:20:49
问题 I'm trying to get a reference to the DOM element for a component in an Angular 2 template using a template reference variable. This works on normal html tags but has a different behaviour on components. e.g. <!--var1 refers to the DOM node --> <div #var1></div> <!--var2 refers to the component but I want to get the DOM node --> <my-comp #var2></my-comp> Is there any way force the template reference variable to refer to the DOM node even if it is on a component? And if so is it covered in the

Concat classname with variable Angular 2

别来无恙 提交于 2020-03-21 17:49:29
问题 I want something like class = "myClass {{classVar}}" I am trying to concat class name with variable value in scope but not working. <div *ngFor="let classVar of classList" > <span [ngClass]="'myClass' classVar "></span> </div> 回答1: Add a + and a space: <div *ngFor="let classVar of classList" > <span [ngClass]="'myClass ' + classVar"></span> </div> 回答2: You can use it like : [ngClass]="'myClass' + classVar " OR ngClass="myClass {{ classVar }}" OR [class]="'myClass' + classVar " OR class=

How do I dynamically load and display html which contains routerLink directives in Angular 2?

旧时模样 提交于 2020-02-22 06:21:45
问题 I have an Angular 2 component which, on some user action, loads html from a database. The html contains anchor tags with relative paths. Given that I don't want the whole application to reload when the user clicks the link, I am trying to use the routerLink directive; however, since this html is loaded dynamically, the routerLink is not processed. The html will not contain any other angular directives. What is the simplest way to achieve this? See my example below. import { Component } from '

Md-menu closes after clicking md-tab inside

我只是一个虾纸丫 提交于 2020-02-21 13:46:45
问题 I built an md-menu with an md-tab-group inside, using Angular Material 2. On each md-tab I display a different list. The behavior I'm expecting to see is that the user to be able to switch between tabs and the md-menu to stay opened. The thing is that the md-menu closing on every click on one of the tabs. <img src="/assets/images/ic-notifications.png" [mdMenuTriggerFor]="appMenu"/> <md-menu #appMenu="mdMenu" [overlapTrigger]="false" yPosition="below" xPosition="before" class="notifications

Angular2 : No provider for String! (child -> String) in [Array in parent

怎甘沉沦 提交于 2020-02-02 04:25:32
问题 Im building basic Todo App in angular2 when I click add button to send data from parent to child using input I get No provider for string! (child->string), and no data displayed only button at the child class is shown, what does it mean here is parent component: @Component({ selector : 'parent-component', directives : [child], template : ` <h1 class= "text-center">ToDo App</h1> <div class = "form-group"> <lable>Task</lable> <input type = "text" class = "form-control" #task> <lable>Detail<

Angular2 : No provider for String! (child -> String) in [Array in parent

白昼怎懂夜的黑 提交于 2020-02-02 04:25:22
问题 Im building basic Todo App in angular2 when I click add button to send data from parent to child using input I get No provider for string! (child->string), and no data displayed only button at the child class is shown, what does it mean here is parent component: @Component({ selector : 'parent-component', directives : [child], template : ` <h1 class= "text-center">ToDo App</h1> <div class = "form-group"> <lable>Task</lable> <input type = "text" class = "form-control" #task> <lable>Detail<

How to catch routes in *ngIf

余生长醉 提交于 2020-02-01 19:00:13
问题 So I want to make an anchor element on my Header disappear when a specific page is hit. How can I catch the url in the *ngIf when that page is hit. I have a header which will remain same for all pages. Just need to hide an anchor element when I am routed at /home. How to catch this "/home" in *ngIf? *ngIf = "href='/home'" is not working. Any alternatives? 回答1: //mycomponent.component.ts class MyComponent { constructor(private router: Router){ } } //mycomponent.component.html <div *ngIf=

how to use parent module component in child module component in angular2

和自甴很熟 提交于 2020-01-31 06:47:47
问题 I have header that should be used in both child and parent module.that was imported and used in parent module but when try to import and using in child component it showing error.I mean how to use common header for both parent and child module Uncaught (in promise): Error: Type HeaderComponent is part of the declarations of 2 modules: AppModule and ProviderModule! Please consider moving HeaderComponent to a higher module that imports AppModule and ProviderModule. You can also create a new

how to use parent module component in child module component in angular2

帅比萌擦擦* 提交于 2020-01-31 06:47:11
问题 I have header that should be used in both child and parent module.that was imported and used in parent module but when try to import and using in child component it showing error.I mean how to use common header for both parent and child module Uncaught (in promise): Error: Type HeaderComponent is part of the declarations of 2 modules: AppModule and ProviderModule! Please consider moving HeaderComponent to a higher module that imports AppModule and ProviderModule. You can also create a new