angular-components

angular2 router navigation does not load component properly

依然范特西╮ 提交于 2019-12-07 23:06:40
问题 My code for that is as shown below: googleClick(): void { this._auth.login('google').subscribe( (data: any) => { console.log('google server data ' + JSON.stringify(data)); this.loginService.registerUser(data.email, data.name, '0').subscribe(res => { if (res.status === '200') { this.storage.store('user_token', res.data.user_token); this.storage.store('user_email', data.email); this.storage.store('user_img', data.image); this.storage.store('user_first_name', res.data.user_name); this.storage

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

╄→尐↘猪︶ㄣ 提交于 2019-12-07 15:40:45
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 and this.good is NOT CHANGED good. It is old good , like it was passed to the component. I started to

How to dynamically create component instance with input/output from a service and inject it to DOM separately?

若如初见. 提交于 2019-12-07 05:13:31
问题 In creating dynamic components in Angular 2, I found out that this process requires ViewContainerRef in order to add newly created component to DOM. And in passing @Input and @Output to those dynamically created components, I found the answer in the second link above and here. However, if I were to create a service named shape.service that contains functions returning different shape components with some @Input like bgColor , I don't know how this service will create a component without

How to use content projection (aka transclusion) in Angular

只谈情不闲聊 提交于 2019-12-07 03:15:28
I am new to angular 4. I have a doubt in angular 4 embedded components. example: <hero-list> <hero></hero> <hero></hero> </hero-list> I wanted to know how to create a view based on this structure that is embedding component inside another component. You should use <ng-content></ng-content> in your hero-list -component. So you can realize your wish above. hero-list.component.html <div class="hero-list"> <h1>Hero list</h1> <ng-content></ng-content> </div> And now you can wrap your hero-item -components and they will be printed inside of hero-list component. app.component.html <hero-list> <hero

How to reload the current Angular 2 Component

自作多情 提交于 2019-12-07 03:13:15
问题 How can I reload the same component again in Angular 2? Here is my code below: import { Component, OnInit, ElementRef, Renderer } from '@angular/core'; import { Router, ActivatedRoute, Params } from '@angular/router'; import { productModel } from '../_models/index'; import { categoryListService } from '../_services/index'; @Component({ selector: 'app-product', templateUrl: 'product.component.html', styleUrls: ['product.component.css'] }) export class productComponent implements OnInit {

Angular @Input getter/setter and non-primitive values

こ雲淡風輕ζ 提交于 2019-12-07 01:54:07
问题 The Problem: I want be able to call a function each time a property in the object the child component is bound to changes. However, the setter is only called once, even though the bound input property can visibly be seen updating. This all came to be from the need to have a child component bind to its parent components property that happens to be a complex object with deeply nested properties. I've learned that the Angular onChange event does not fire when a nested property in an object

How to reset only specific fields of form in angular 5

主宰稳场 提交于 2019-12-06 22:44:58
问题 I have created a function in one of my component file that resets the form(myform): `onSubmit() { if (this.myform.valid) { console.log("Form Submitted!"); this.myform.reset(); } }` It works perfectly fine resetting the whole form, but is it possible to just reset some of the elements and keeping other the same way. 回答1: try this: this.myform.controls['comments'].reset() 回答2: try this one: clearForm() { this.myForm.get('comments').reset(); this.myForm.get('name').reset(); } and call this

How can I access from a child component to another child component in Angular 4 [duplicate]

。_饼干妹妹 提交于 2019-12-06 13:20:35
问题 This question already has answers here : How can I communicate between two child components in angular? [duplicate] (4 answers) Closed 2 years ago . I have a parent component and inside there are 2 different child components. I need to call the second child component's function from the first child component when I click a link in the first child component. So here is a basic diagram to explain better: 回答1: You could archieve this by means of ViewChild and Output For example: @Component({

How to check if a component exists in Angular 1.5

给你一囗甜甜゛ 提交于 2019-12-06 09:26:28
http://embed.plnkr.co/oGlcQSOM2vFcDEKP7thV/ $injector.has('myMessageDirective') returns true, while $injector.has('myMessageComponent') does not Is anyone struggling with this or has a solution? My "fear" is that my components might not be found in future updates because of the directive check. Follow up question to: Check if an Angular directive exists At the end of the day, a component is registered as a directive, so 'Directive' suffix is indeed needed. Check 'has' method of $injector object: return { invoke: invoke, instantiate: instantiate, get: getService, annotate: createInjector.$

angular2 router navigation does not load component properly

浪子不回头ぞ 提交于 2019-12-06 09:11:36
My code for that is as shown below: googleClick(): void { this._auth.login('google').subscribe( (data: any) => { console.log('google server data ' + JSON.stringify(data)); this.loginService.registerUser(data.email, data.name, '0').subscribe(res => { if (res.status === '200') { this.storage.store('user_token', res.data.user_token); this.storage.store('user_email', data.email); this.storage.store('user_img', data.image); this.storage.store('user_first_name', res.data.user_name); this.storage.store('user_id', res.data._id); this.storage.store('user_paltform_login', 0); this.router.navigate(['