0

I currently use this code snippet to get the parallax effect:

ngAfterViewInit(){
  if(isBrowser) {
    $('.parallax').parallax();
  }
}

I want to know if there is another way to use the jquery plugins and not have to validate on all the components with isBrowser

WillardSolutions
  • 2,316
  • 4
  • 28
  • 38
yamidvo
  • 661
  • 1
  • 5
  • 12

1 Answers1

0

Relevent solution.

His solution is more centered around finding out if the broswer is IE, but contains code that can also apply to you.

app.service('browser', ['$window', function($window) {

 return function() {

    var userAgent = $window.navigator.userAgent;

    var browsers = {chrome: /chrome/i, safari: /safari/i, firefox: /firefox/i, ie: /internet explorer/i};

    for(var key in browsers) {
        if (browsers[key].test(userAgent)) {
            return key;
        }
   };

   return 'unknown';
 }

}]);
Community
  • 1
  • 1
Code Eyez
  • 313
  • 3
  • 14
  • This answer seems to target AngularJS 1.x, where the OP is asking about Angular 2+ (see the tag angular-universal and `ngAfterViewInit`) – Joe Skeen Sep 01 '17 at 17:14