To set up a condition in your Angular controller, you can create a scoped variable like this:
angular.module('myApp', []).controller('MyCtrl', ['$scope', function( $scope ) {
$scope.isChrome = /chrome/i.test(navigator.userAgent);
});
In your view, you can then use the variable like so:
<div data-ng-show="isChrome">You're using Chrome!</div>
If you require a variable that needs to be accessible across controllers, you can utilize a Service:
angular.module('myApp', []).factory('UAService', function() {
return {
isChrome: /chrome/i.test(navigator.userAgent)
};
});
You can inject and use this service in your controllers like this:
angular.module('myApp', []).controller('MyCtrl', ['$scope', 'UAService', function( $scope, UAService ) {
$scope.UAService = UAService;
});
Now, you can access the service from any scope within the scope created by your top-level controller:
<div data-ng-show="UAService.isChrome">You're running Chrome!</div>