-
Notifications
You must be signed in to change notification settings - Fork 5
/
uiGoto.js
30 lines (23 loc) · 1 KB
/
uiGoto.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
angular.module('mgo.ui.router.directives', ['ui.router']);
angular.module('mgo.ui.router.directives').directive('uiGoto', function() {
return {
restrict : 'A',
controller: ['$scope', '$element', '$attrs', '$state',
function ($scope, $element, $attrs, $state) {
$element.bind('click', function(e) {
e.preventDefault();
var state = $attrs.uiGoto;
var params = {};
if ($attrs.uiGotoParams) {
var params = $scope.$eval($attrs.uiGotoParams);
if (!angular.isObject(params)) {
throw new Error("Parameters for uiGotoParams must be an object");
}
}
$scope.$apply(function() {
$state.transitionTo(state, angular.extend({}, $state.params, params));
})
});
}]
}
});