logo
down
shadow

Angular onInit doesn't get called when URL param changes


Angular onInit doesn't get called when URL param changes

By : Alex Galie
Date : August 21 2020, 09:00 PM
I think the issue was by ths following , I have a path structure like this: /item/:id/editItem. In the component on the URL /item I have multiple buttons with an onclick function like this: ,
ngOnInit()
code :
class MyClass {
  constructor(private router: Router) {
    router.events.subscribe((val) => {
        // see also 
        console.log(val instanceof NavigationEnd) 
    });
  }
}


Share : facebook icon twitter icon
SAPUI5 keydown in onInit not called

SAPUI5 keydown in onInit not called


By : Messias
Date : March 29 2020, 07:55 AM
I wish this help you You should execute your code snippet on the onAfterRendering lifecycle hook. This is because in the onInit, the jQuery call will not be able to find any input (as the elements corresponding to your view were not yet added to the DOM).
Based on the description and code, I understand that you need to check if the F11 + CTRL was pressed (hence the check is evt.keyCode == 122 && evt.ctrlKey); if you want a sinple F11, the you only need to check evt.keyCode == 122.
code :
 onAfterRendering: function() {
   jQuery("input").on("keydown",
     function(evt) {
       if (evt.keyCode == 122 && evt.ctrlKey) {
         evt.preventDefault();
         sap.m.MessageToast.show('Alert');
       }
     });
 }
var CustomInput = sap.m.Input.extend("CustomInput", {
   metadata: {
     events: {alert: {}}
   },
   onkeydown: function(evt) {
     if (evt.keyCode == 122 && evt.ctrlKey) {
       // only prevent the default of the DOM event if the
       // UI5 event's preventDefault is called as well.
       if (!this.fireEvent("alert", {}, true)) {
           evt.preventDefault();
       }
     }
   },
   renderer: {}
});
How to call a specific promise only once in Angular 1.5 when onInit hook is called multiple times

How to call a specific promise only once in Angular 1.5 when onInit hook is called multiple times


By : Jaquan
Date : March 29 2020, 07:55 AM
hop of those help? There is a API call that I am making on the onInit function. , I advice wrapping the API call in a service like:
code :
(function (angular) {
    'use strict';

    angular
        .module('services.common')
        .service('TimesService', TimesService);

    TimesService.$inject = ['HttpWrapper'];

    function TimesService(HttpWrapper) {
        var timesService = this;
        var timesResult = null;

        timesService.getTimes = getTimes;

        function getTimes() {
            if (!timesResult) {
                timesResult = HttpWrapper.send('/api/times/cst', {"operation": 'GET'});
            }
            return timesResult;
        }

        return timesService;
    }

})(angular);
Angular service passing integer url params getting called twice appending Param value to API call

Angular service passing integer url params getting called twice appending Param value to API call


By : Partha Ghosh
Date : March 29 2020, 07:55 AM
this one helps. That ngOninit() is called twice is a different issue. The different query string param is caused by
code :
this.url = `${this.Url}${id}`
let url ="..getdetails?id="
let id = 1;

url = `${url}${id}`;
console.log(url);
url = `${url}${id}`;
console.log(url);

function setUrl(id) {
  console.log('Within a function...');

  let url = "..getdetails?id="

  url = `${url}${id}`;
  console.log(url);

}

setUrl(1);
setUrl(1);
$ node app.js
..getdetails?id=1
..getdetails?id=11
Within a function...
..getdetails?id=1
Within a function...
..getdetails?id=1
 setUrl(url:string, id:number) { 
  url = `${url}${id}`;
  console.log(url);
  return url;
}

getProducts(url:string, id: number): Observable<Products> {

  return this.http.get<Products>(this.setUrl(url, id));
}
UI5 - navTo doesnt launch onInit event on page which wasnt displayed yet

UI5 - navTo doesnt launch onInit event on page which wasnt displayed yet


By : user2853112
Date : March 29 2020, 07:55 AM
will help you OK, problem solved. As I said, the problem was that the onInit was not even executed. It was caused by a bug I made, forgot to change the initial line when I was copypasting the code - so both items list and items details were extending the same controller in the beginning, forgot to rewrite the code for item details.
code :
`return BaseController.extend('xxx.portal.controller.item.itemList', {
Angular OnInit : Values returned from Service subscribe returns Empty blank because API has not Called yet

Angular OnInit : Values returned from Service subscribe returns Empty blank because API has not Called yet


By : user3371390
Date : March 29 2020, 07:55 AM
it should still fix some issue check this stackblitz for reference StackBlitz Link
here, you have to use map inside pipe operator of rxjs.
code :
getAllData(){
return this.http.request <any[]> ('get', "https://raw.githubusercontent.com/lewagon/flats-boilerplate/master/flats.json")
.pipe( 
       map(data => {
       console.log('map data' + data);
       return data;
       })
 )
 ngOnInit(){
     this.dataService.getAllData().subscribe( (data) => {
           console.log('server data' + data);
           this.serviceData = data;
     }) 
 }
 <div *ngFor="let data of serviceData ; let i=index">
       <span> {{i+1}} </span> {{data.name}}
 </div>
Related Posts Related Posts :
  • How to update all ionic cordova plugin at one command in Ionic-V4
  • How to give dynamics values for [routerLink] which it corresponds to values of an array?
  • Add and delete item from an array
  • How to unit test a button within an ngfor
  • How to launch a method after a cell value has been edited in ag-grid?
  • Can't select individual user accounts when creating a new Asp.Net Core 2.1 Angular project in Visual Studio 2019
  • How do I get the response code in angular 7
  • Angular PrimeNg: p-table not detected using @ViewChild
  • How to route within the tab component in ionic
  • How can i combine data from two API's into datasource
  • Find the last index from the array using ngFor
  • ngSelect always return undefined
  • Nested Forms in Angular Material Stepper trigger a ExpressionChangedAfterItHasBeenCheckedError
  • Angular library dependency exposure
  • Handling errors with RxJS and Angular async pipe
  • Kubernetes internal CORS issues between services
  • Ionic set marker on location or based on longitude and latitude
  • CAN NOT expand Angular Material table
  • Share a angular library across multiple projects
  • How to import pipe to 2 modules(AppModule and ChildModule)?
  • How to disable the drag option on Angular material Slide toggle component
  • Does Spartacus support Hybris on-premise?
  • Bind regular expression from json to typescript
  • How can i get the selected value in ion-alert radio alert
  • How to get all attributes of an object
  • Using angular elements inside the same angular project
  • RxJS assign observable and get data in one stream
  • Why I can not use anguar/material elements?
  • Getting Error when running 'ng test' Command
  • How can I make another request within catchError?
  • angular 7 input number validation
  • Dont show digits after decimal using angular pipe
  • How to use same component in normal way and with angular material dialog both?
  • How to integrate ReSharper with WebStorm
  • Google cloud application yaml for angular 7
  • How to perform concurrent HTTP requests on rows of a table
  • Angular 7 - deploy workspace applications (projects) in isolation
  • how to turn off differential loading in Angular v8?
  • How to add and update npm packages for a new Angular app in Visual Studio 2019
  • Angular 7, Ngrx, Rxjs 6 - Accessing state between lazy loaded modules
  • cannot find symbol import com.google.firebase.iid.FirebaseInstanceIdService error in ionic3
  • AWS CodePipeline, build failed and getting error
  • CORS problem with Angular and laravel even after setting the CORS header and server response
  • Angular, when the variable is mentioned in the url, the variable is not replaced with its value. Ex: ${username}
  • How to apply two ngIf on single html element with two different conditions
  • Ionic not importing ngx-mathjax module
  • How to display base64 image on iPhone in Ionic 4
  • ngFor in columns with diferents properties
  • How catch the http errors with map
  • How to format a Date field in Angular project
  • focusing ng-select filter input on drop down open
  • Angular 7 PDFJS Component
  • NestJs Errors stemming from @types dependencies in node_modules when running start:prod on fresh project
  • How to override ion-back-button action in ionic 4 with angular 7
  • How can I have an array in input form?
  • Angular 6 component test with a variable into HTML
  • Why is ES7/array polyfill needed despite the tsconfig target is set to ES5
  • How to deal with Google recaptcha backend validation response delay
  • Logging in using @angular/fire/auth results in 403 error on localhost
  • In Angular, with ViewChild/ ViewChildren, how do I get the child of a child?
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk