angular-components

Import 3rd party javascript libraries in Angular single components

拟墨画扇 提交于 2019-12-11 02:35:46
问题 I'm currently developing an Angular4 application and I want to import some javascript libraries but just for a single component . Currently I can easily import this libraries by defining their paths inside .angular-cli.json like that: { "scripts": [ "../node_modules/jquery/dist/jquery.min.js", "../node_modules/jqueryui/jquery-ui.js", "../src/assets/js/jquery/cometd/org-cometd.js", "../src/assets/js/jquery/cometd/jquery.cometd.js", ], ... } However, the mentioned scripts will be imported for

Angular folder structure and component services

故事扮演 提交于 2019-12-10 15:26:07
问题 I have read many articles about Angular folder structure. It is still not clear to me where do we put component services. Shared services between components are put under shared. But what about a service that is used only by a component? Usually I put all my component logic into a service and leave the component with code relevant only to UI stuff. Which one is better to use: Each component and its service into the same folder --app.component.html --app.component.ts --app.module.ts --app

Angular 2+: Get child element of @ViewChild()

馋奶兔 提交于 2019-12-10 14:28:36
问题 How can I access the child elements (here: <img> ) of @ViewChild() in Angular 2+ without explicit declaration? In template.html <div #parent> <!-- There can be anything than <img> --> <img src="http://localhost/123.jpg" alt=""> </div> In component.ts @ViewChild('parent') parent; public getFirstChild() { this.firstChild = this.parent.? // } The aim is, to be able to create a universal component that uses: <div #parent> <ng-content></ng-content> </div> So the child elements of #parent need to

Angular2 CUSTOM_ELEMENTS_SCHEMA Doesn't Work

不羁的心 提交于 2019-12-09 17:25:48
问题 I have just installed a bearbones ng2 app using the ng2 cli. In my AppModule I added schema: [ CUSTOM_ELEMENTS_SCHEMA ] , and in my AppComponent template I have <row></row> . But I'm getting- Unhandled Promise rejection: Template parse errors: 'row' is not a known element: 1. If 'row' is an Angular component, then verify that it is part of this module. 2. If 'row' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message. ("

Is there a way to lazy load components, not modules, in Angular?

孤街醉人 提交于 2019-12-09 14:29:29
问题 Lazy loading is a commonly used technique. However, in Angular it seems that the granularity level of this technique stops at the module level. That means that you can have module main that loads in the browser, and then on special occasion module B and C and D can be loaded lazily. Almost all tutorials on web explain that. However, is there a way to load components lazily? Consider this simple example that user goes inside the application, and when clicks "invoices" link, URL changes to the

Angular 2: Add directive to dynamically created component(s)

左心房为你撑大大i 提交于 2019-12-08 18:18:25
问题 I came across the following Plunker to dynamically add and remove components. According to the above link and from many other SO posts, I know how to access Input and Output properties: this.compRef.instance.someProperty = 'someValue'; this.compRef.instance.someOutput.subscribe(val => doSomething()); And I also have a directive "appFont". import { Directive, ElementRef } from '@angular/core'; @Directive({ selector: '[appFont]' }) export class HighlightDirective { constructor(el: ElementRef) {

Submitting form with enter key in Angular unit test

会有一股神秘感。 提交于 2019-12-08 16:58:52
问题 I'm writing a test for an Angular 4 component that is a login form. The form can be submitted by clicking on the "submit" button or by hitting enter in any input fields. This behaviour is dictated by the Angular form directive. I can write a test case that validates that a button click submits the form, but I can't trigger the submit behaviour with a keypress event. Template: <form (ngSubmit)="onLoginSubmit()" #loginForm="ngForm"> <div class="form-group"> <label for="userid">User ID</label>

Angular 6 router link issue in the same page

浪子不回头ぞ 提交于 2019-12-08 07:53:32
问题 I have two links: ['/productlist',1000] ['/productlist',1001] These two links are on the same page. If I click on any link for the first time. It is redirecting to the page, but if I click on the other link it is not working. component.html code <a class="dropdown-item" (click)="GetProductList(subitem.SubCategoryID)"> <i class="mdi mdi-chevron-right" aria-hidden="true"></i> {{ subitem.SubCategoryName}} </a> GetProductList(SubCategoryID){ this.router.navigate(['/productlist',SubCategoryID]); }

How does Angular destroy event handlers and property bindings when a component is destroyed

纵然是瞬间 提交于 2019-12-08 05:01:13
问题 I am trying to understand the destruction process of Angular Components a bit more detailed than what I could find in the documentation. I was hoping someone here would be able to answer the following questions: Are properties on elements in the Component template removed before the event listeners of such elements are removed? In the destruction process of a Component, when and how does the de-registration of an event listener happen? Is there any more information available concerning the

How to correctly pass props to a component with RxJS in Angular 4?

本小妞迷上赌 提交于 2019-12-08 03:38:01
问题 Here is my component: @Component({ selector: 'bc-goods-detail', template: ` <span>good id: {{good?.id}}</span> <input [value]="good?.name" (input)="onInput($event)" /> <button (click)="onClick()">Save</button> `, styles: [] }) export class GoodsDetailComponent { @Input() good: Good; @Output() save = new EventEmitter<Good>(); onClick() { this.save.emit(this.good); } onInput ($event) { this.good.name = $event.target.value; } } When I change the name in input and then I am pressing save button