angular-components

Passing Data From Child Component Into Parent Component

a 夏天 提交于 2019-12-06 00:29:01
问题 I have problems with my angular, here I have two components: MyApp (ParentComponent) LoginPage (ChildComponent) I have a property UserNow in parts MyApp and I want to set the value of the property UserNow through the components LoginPage . How to do it? I have tried (but did not give any influence) Import {MyApp} from '../../app/app.component'; @Component({ selector: 'page-login', templateUrl: 'login.html' }) export class LoginPage { public app: any; login() { ... this.app = MyApp; this.app

Angular 4 - Pass an object from one component to another (no parent - child hierarchy)

白昼怎懂夜的黑 提交于 2019-12-06 00:11:39
问题 My situation: I have a component showing tiles with each tile representing an object from an array that is looped over with an ngfor. When a tile is clicked I want to pass the object to a different component, which is responsable for displaying all properties of that object in fields that can be modified. What I have tried: After doing some research and coming across multiple posts showing me how to achieve this for a parent - child hierarchy and some posts explaining that it is necessary to

Can't add a new component to my angular 2 app with typescript

眉间皱痕 提交于 2019-12-05 10:48:59
问题 I'm using Angular 2 CLI and I created the component "MyComponent" with the ng generate component MyComponent . As far as I know I have to add the component to the directive key-value-pair of the @Component decorator, but the typescript compilation fails at this point, saying that: ERROR in [default] /Users/Philip/Desktop/Angular2/src/app/app.component.ts:8:2 Argument of type '{ selector: string; template: any; styles: any[]; directives: typeof MyComponentComponent[]; }' is not assignable to

Angular @Input getter/setter and non-primitive values

你说的曾经没有我的故事 提交于 2019-12-05 09:10:44
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 changes. Hence the decision to use getters/setters instead. However, as seen by this question using getters

Angular 6 Convert an Application to Library

╄→гoц情女王★ 提交于 2019-12-05 08:24:47
问题 I have an Angular 6 app that handles routes like 'page-not-found', 'error', 'unauthorized.' This how my routes look: const appRoutes: Routes = [ { path:'page-not-found', component: NotFoundPageComponent }, { path: 'unauthorized', component: UnAuthorizedPageComponent }, { path: 'error', component: ErrorPageComponent }, { path: '**', component: NotFoundPageComponent }, ]; All the components have simple html template like below: <p>Page Not Found. Please report this error to system administrator

How to reload the current Angular 2 Component

瘦欲@ 提交于 2019-12-05 06:18:16
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 { uidproduct: productModel; param: number; constructor( private elementRef: ElementRef, private route:

How to reset only specific fields of form in angular 5

老子叫甜甜 提交于 2019-12-05 03:38:15
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. try this: this.myform.controls['comments'].reset() try this one: clearForm() { this.myForm.get('comments').reset(); this.myForm.get('name').reset(); } and call this function where you submit form. Yes you can access the controls using tnis.myform.controls get the control and call

Angular's `@Host` decorator not reaching the top?

老子叫甜甜 提交于 2019-12-05 01:16:04
问题 In my main app.ts I've declared a global provider : providers: [{provide: Dependency, useValue: createDependency('AppModule provider')}] ( Where createDependency is just a function that returns a class which has a getName() method. ) I also have a components : <my-app-component-3>Hello from 3</my-app-component-3> Code : @Component({ selector: 'my-app-component-3', template: ` <div>Component3: <ng-content></ng-content> : <span [innerHTML]="dependency?.getName()"></span> </div> `, }) export

Angular 4 call directive method from component

冷暖自知 提交于 2019-12-05 00:49:52
i'm trying to build a structural directive that will change the parent DOM structure either invoked by using its selector (static) or by calling its public method(dynamic). Using the directive selector in a html template works fine without any issues. I'm trying to figure out if we an achieve the same without using it in template and by calling the directive method. my-directive.ts @Directive({ selector: '[sampleDirective]' }) export class SampleDirective { ... constructor(..) { this.customDirective(); } } customDirective() { console.log('Inside customDirective()'); } my-component.ts import {

In Angular, how do I insert specific component instances without using directives/templates?

徘徊边缘 提交于 2019-12-04 23:26:25
问题 So, let's say I have a component, ExampleComponent , that builds a QueryList of SomeOtherComponent components in its content view. import {Component, ContentChildren, QueryList} from '@angular/core' import {SomeOtherComponent} from '../some-other-component/some-other-component.component' @Component({ selector : 'app-example', templateUrl: './example.component.html', styleUrls : ['./example.component.css'] }) export class ExampleComponent { @ContentChildren(SomeOtherComponent)