spyOn not able to spy on the method of a dependent service

Issue I am testing AuthService which sends user login info to server using another HelperService. public authServiceSigninUser(user:UserSigninInfo):any{ console.log(‘In authServiceSigninUser. contacting server at ‘+this.API_URL +this.SIGNIN_USER_URL +” with user data “+user+ ” with httpOptions “+httpOptions.withCredentials + “,”+httpOptions.headers ); //TODOM password should be

Continue reading

unable to mock HttpClient in Jasmine and Karma using HttpTestController

Issue I am testing AuthService which sends user login info to server using another HelperService. public authServiceSigninUser(user:UserSigninInfo):any{ console.log(‘In authServiceSigninUser. contacting server at ‘+this.API_URL +this.SIGNIN_USER_URL +” with user data “+user+ ” with httpOptions “+httpOptions.withCredentials + “,”+httpOptions.headers ); //TODOM password should be

Continue reading

how to unit test subscription to a BehaviourSubject in angular

Issue I have a UserManagementService which exposes an Observable of a BehaviourSubject. this.userSignInState$ = this.signInStateSubject.asObservable(); I subscribe to userSignInState in a nav component. constructor(public userManagementService: UserManagementService, private fb:FormBuilder, private helper:HelperService) { this.userSignInStateSubscription = this.userManagementService.userSignInState$.subscribe( (result:Result)=> { console.log(“In nav – result

Continue reading

RouterTestingModule not providing provider for Location

Issue I am unit-testing a Component which uses two other components. The other components are created when button is clicked .html <div id=”homepage-top-div” class=”homepage-component-css-grid-container”> … <button id=”get-question-list-button” [routerLink]=”questionListRouterLink” class=”btn content-div__button–blue css-grid-item-button-div btn-sm”>See Questions</button> </div> <div id=”practice-component-top-div” class=”css-grid-container-div common-styles-div–white”> <!– 4

Continue reading

Angular 6: get reference to Components created with *ngFor inside ng-container tag

Issue I’using ng-container to iterate on a list and create components <ng-container *ngFor=”let f of optionsList; let i = index;”> <!– component–> <app-component #fieldcmp *ngIf=”isAppComponent(f)” ></app-field> <!–another components–> <app-anoter-component1 *ngIf=”isAnotherComponent1(f)”> </app-anoter-component1> … <app-anoter-componentn *ngIf=”isAnotherComponentn(f)”> </app-anoter-componentn> </ng-container> I would to list

Continue reading

Angular 6 FormArray discard null fields

Issue I’m using Angular 6. I have a FormArray array like below contactAddForm: FormGroup; phone_numbers: FormArray; ngOnInit() { this.contactAddForm = this.formBuilder.group({ first_name: new FormControl(”, [ Validators.required ]) phone_numbers: this.formBuilder.array([this.createPhoneNumberFormField()]) }); } createPhoneNumberFormField(): FormGroup { return this.formBuilder.group({ phone: new FormControl(), primary:

Continue reading

ngOnInit is calling before resolver data is ready

Issue I have a resolve that is calling getSchools() from service resolver.ts export abstract class APIResolverService implements Resolve<any> { constructor(readonly dropdownService:DropDownOptionsService,readonly route:ActivatedRoute) { } abstract resolve(); } export class APISchoolsresolve extends APIResolverService{ resolve(){ this.route.queryParams.subscribe(params => { let district = params[‘district’];

Continue reading

Get current active child component in Angular 6

Issue I’m using Angular 6. I have created a deep routing in my application where app.module a declaration with component AdminLayout @NgModule({ declarations: [ AppComponent, AdminLayoutComponent, ], imports: [ BrowserModule, AppRoutingModule, RouterModule.forRoot([]), ComponentsModule, ] }); and further AdminLayoutComponent is a

Continue reading

Lazy module can not be found although path seems correct

Issue link: https://play.nativescript.org/?template=play-ng&id=Annyna&v=4 error: ERROR Error: Uncaught (in promise): Error: com.tns.NativeScriptException: Failed to find module: “./TrainingUnit”, relative to: app/trainingunit/list/ Its odd that the module name in the error message is: “./TrainingUnit” The module file name is: trainingunit.module The module class

Continue reading

ng-bootstrap Change default color of radio button

Issue I am new to ng-bootstrap. Default color of radio buttons in ng-bootsrap is blue. I need default color as yellow and on click it should be green. buttons-radio.html <div class=”btn-group btn-group-toggle” ngbRadioGroup name=”radioBasic” [(ngModel)]=”model”> <label ngbButtonLabel class=”btn-primary”> <input ngbButton

Continue reading

Conditional reset method "if disable ignore not disable reset" angular

Issue <div> <div> <label>Name</label> <input type="text" [(ngModel)]="name" [disabled]="editData" </div> <div> <label>address</label> <input type="text" [(ngModel)]="address" </div> </div> <button (click)=add() >add</button> <button (click)=edit()>edit</button> <button (click)=reset()>reset</button> Note:- On add() both fields should be reset but on edit only address field should be reset

Continue reading

Geting object, both id and value from ngFor on button click angular 6

Issue this is html code <tr> <td>Select New Subject:</td> <td> <Select name=”DesiredSubject” [(ngModel)] = “sub” ngDefaultControl> <option [value]=”0″>–Select Subject–</option> <option *ngFor =”let subj of subjects” [value]=”subj”>{{subj.bank_Name}}</option> </Select> </td> </tr> <tr> <td>Action :</td> <td><button value=”Update Subject” (click)=”changeSubject(sub)”>Update Subject</button></td> </tr> and this

Continue reading

Remove duplicate names in a column

Issue In my angular 6 application, i am making a table with the contents from products array like, Ts: products: any = { “productOne”: [ { “id”: 1, “product_name”: “Product One”, “productOneProperties”: [ { “id”: 1, “property_name”: “Length”, “property_value”: “12cm”

Continue reading

How to loop over multiple tr's with *ngFor & *ngIf

Issue This sample of the template <div *ngFor=”let order of orders” class=”col-1-4″> <tr *ngIf=”order.user_id===user”> <td> {{ order.package_id }} </td> <td> <img src=”{{order.img}}” width=”100″ height=”120″></td> <td>{{ order.name }}</td> <td>{{ order.price }}</td> <td>{{ order.size_i }}</td> <td>{{ order.size_s }}</td> <td>{{ order.color }}</td> <td>{{

Continue reading

How to validate custom input textbox in angular 7

Issue I am trying to show template driven validate error message for custom textbox in angular 7 but not working.Anyone can find the issue?how to resolve this issue? Demo:https://stackblitz.com/edit/angular-7-template-driven-form-validation-yzcwqc?file=app%2Fapp.component.html app.component.html: <div class=”form-group”> <label for=”firstName”>First Name</label> <app-textbox type=”text” name=”firstName” [(ngModel)]=”model.firstName” #firstName=”ngModel”

Continue reading