Angular js – route-ui add default parmeter

There is a working plunker As always, that is feasible with UI-Router – built in features. Firstly, we’d introduce the super parent state called for example ‘root’. It would have defined parameter lang .state(‘root’, { url: ‘/{lang:(?:en|he|cs)}’, abstract: true, template: ‘<div ui-view=””></div>’, params: {lang : { squash : true, value: ‘en’ }} }) Interesting things … Read more

How to pass parameters using ui-sref in ui-router to the controller

I’ve created an example to show how to. Updated state definition would be: $stateProvider .state(‘home’, { url: ‘/:foo?bar’, views: { ”: { templateUrl: ‘tpl.home.html’, controller: ‘MainRootCtrl’ }, … } And this would be the controller: .controller(‘MainRootCtrl’, function($scope, $state, $stateParams) { //.. var foo = $stateParams.foo; //getting fooVal var bar = $stateParams.bar; //getting barVal //.. $scope.state … Read more

Can you override specific templates in AngularUI Bootstrap?

Yes, directives from http://angular-ui.github.io/bootstrap are highly customizable and it is easy to override one of the templates (and still rely on the default ones for other directives). It is enough to feed $templateCache, either feeding it directly (as done in the ui-bootstrap-tpls file) or – probably simpler – override a template using the <script> directive … Read more

How to reload the current state?

I found this to be the shortest working way to refresh with ui-router: $state.go($state.current, {}, {reload: true}); //second parameter is for $stateParams Update for newer versions: $state.reload(); Which is an alias for: $state.transitionTo($state.current, $stateParams, { reload: true, inherit: false, notify: true }); Documentation: https://angular-ui.github.io/ui-router/site/#/api/ui.router.state.$state#methods_reload

How to use a keypress event in AngularJS?

You need to add a directive, like this: Javascript: app.directive(‘myEnter’, function () { return function (scope, element, attrs) { element.bind(“keydown keypress”, function (event) { if(event.which === 13) { scope.$apply(function (){ scope.$eval(attrs.myEnter); }); event.preventDefault(); } }); }; }); HTML: <div ng-app=”” ng-controller=”MainCtrl”> <input type=”text” my-enter=”doSomething()”> </div>

How to pass parameters using ui-sref in ui-router to controller

I’ve created an example to show how to. Updated state definition would be: $stateProvider .state(‘home’, { url: ‘/:foo?bar’, views: { ”: { templateUrl: ‘tpl.home.html’, controller: ‘MainRootCtrl’ }, … } And this would be the controller: .controller(‘MainRootCtrl’, function($scope, $state, $stateParams) { //.. var foo = $stateParams.foo; //getting fooVal var bar = $stateParams.bar; //getting barVal //.. $scope.state … Read more