Skip to content

Commit

Permalink
Added error handling to sref encountering for errors which seems to b…
Browse files Browse the repository at this point in the history
…reak down the angular $watch...

Instead errors are handed of to the $exceptionHandler service.

This is related to #131 and fixes the issue in there, optionally we still might wan't to allow for silently ignore these errors.
  • Loading branch information
jeme committed Mar 7, 2015
1 parent 98a9b61 commit 44a97ef
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 70 deletions.
45 changes: 16 additions & 29 deletions build/angular-routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ var errors = {
invalidNumericValue: "Value was not acceptable for a numeric parameter.",
invalidBrowserPathExpression: "Invalid path expression.",
expressionOutOfBounds: "Expression out of bounds.",
couldNotFindStateForPath: "Could find state for path."
couldNotFindStateForPath: "Could not find state for path."
};

var EVENTS = {
Expand Down Expand Up @@ -3198,27 +3198,6 @@ var $ScrollProvider = [function () {
}];
}];
angular.module('dotjem.routing').provider('$scroll', $ScrollProvider);
//scroll.$register = register;
//var elements = {};
//function register(name: string, elm: HTMLElement) {
// if (name in elements) {
// var existing = elements[name];
// }
// elements[name] = elm;
//}
/****jQuery( "[attribute='value']"
* scrollTo: top - scroll to top, explicitly stated.
* (This also enables one to override another scrollTo from a parent)
* scrollTo: null - don't scroll, not even to top.
* scrollTo: element-selector - scroll to an element id
* scrollTo: ['$stateParams', function($stateParams) { return stateParams.section; }
* - scroll to element with id or view if starts with @
*/
//scrollTo: top - scroll to top, explicitly stated.(This also enables one to override another scrollTo from a parent)
//scrollTo: null - don't scroll, not even to top.
//scrollTo: @viewname - scroll to a view.
//scrollTo: elementid - scroll to an element id
//scrollTo: ['$stateParams', function($stateParams) { return stateParams.section; } - scroll to element with id or view if starts with @

/// <reference path="refs.d.ts" />

Expand Down Expand Up @@ -3904,6 +3883,10 @@ var jemViewDirective = [
controller = view.controller;

view.template.then(function (html) {
if (scope.$$destroyed) {
return;
}

var newScope = scope.$new();
linker(newScope, function (clone) {
cleanupView(doAnimate);
Expand Down Expand Up @@ -4019,22 +4002,26 @@ angular.module('dotjem.routing').directive('id', jemAnchorDirective);
* @param {string} activeClass Class to add when the state targeted is active.
*/
var jemLinkDirective = [
'$state', '$route',
function ($state, $route) {
'$state', '$route', '$exceptionHandler',
function ($state, $route, $exceptionHandler) {
'use strict';
return {
restrict: 'AC',
link: function (scope, element, attrs) {
var tag = element[0].tagName.toLowerCase(), html5 = $route.html5Mode(), prefix = $route.hashPrefix(), attr = { a: 'href', form: 'action' }, activeFn = isDefined(attrs.activeClass) ? active : noop;

function apply(sref, params) {
var link = $state.url(sref, params);
try {
var link = $state.url(sref, params);

//NOTE: Is this correct for forms?
if (!html5) {
link = link === '' ? '#' + prefix + '/' + link : '#' + prefix + link;
//NOTE: Is this correct for forms?
if (!html5) {
link = link === '' ? '#' + prefix + '/' + link : '#' + prefix + link;
}
element.attr(attr[tag], link);
} catch (err) {
$exceptionHandler(err);
}
element.attr(attr[tag], link);
}

//TODO: Should we depricate this and use filters instead from 0.7.0?
Expand Down
2 changes: 1 addition & 1 deletion build/angular-routing.min.js

Large diffs are not rendered by default.

45 changes: 16 additions & 29 deletions gh-pages/assets/scripts/angular-routing/impl/angular-routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ var errors = {
invalidNumericValue: "Value was not acceptable for a numeric parameter.",
invalidBrowserPathExpression: "Invalid path expression.",
expressionOutOfBounds: "Expression out of bounds.",
couldNotFindStateForPath: "Could find state for path."
couldNotFindStateForPath: "Could not find state for path."
};

var EVENTS = {
Expand Down Expand Up @@ -3198,27 +3198,6 @@ var $ScrollProvider = [function () {
}];
}];
angular.module('dotjem.routing').provider('$scroll', $ScrollProvider);
//scroll.$register = register;
//var elements = {};
//function register(name: string, elm: HTMLElement) {
// if (name in elements) {
// var existing = elements[name];
// }
// elements[name] = elm;
//}
/****jQuery( "[attribute='value']"
* scrollTo: top - scroll to top, explicitly stated.
* (This also enables one to override another scrollTo from a parent)
* scrollTo: null - don't scroll, not even to top.
* scrollTo: element-selector - scroll to an element id
* scrollTo: ['$stateParams', function($stateParams) { return stateParams.section; }
* - scroll to element with id or view if starts with @
*/
//scrollTo: top - scroll to top, explicitly stated.(This also enables one to override another scrollTo from a parent)
//scrollTo: null - don't scroll, not even to top.
//scrollTo: @viewname - scroll to a view.
//scrollTo: elementid - scroll to an element id
//scrollTo: ['$stateParams', function($stateParams) { return stateParams.section; } - scroll to element with id or view if starts with @

/// <reference path="refs.d.ts" />

Expand Down Expand Up @@ -3904,6 +3883,10 @@ var jemViewDirective = [
controller = view.controller;

view.template.then(function (html) {
if (scope.$$destroyed) {
return;
}

var newScope = scope.$new();
linker(newScope, function (clone) {
cleanupView(doAnimate);
Expand Down Expand Up @@ -4019,22 +4002,26 @@ angular.module('dotjem.routing').directive('id', jemAnchorDirective);
* @param {string} activeClass Class to add when the state targeted is active.
*/
var jemLinkDirective = [
'$state', '$route',
function ($state, $route) {
'$state', '$route', '$exceptionHandler',
function ($state, $route, $exceptionHandler) {
'use strict';
return {
restrict: 'AC',
link: function (scope, element, attrs) {
var tag = element[0].tagName.toLowerCase(), html5 = $route.html5Mode(), prefix = $route.hashPrefix(), attr = { a: 'href', form: 'action' }, activeFn = isDefined(attrs.activeClass) ? active : noop;

function apply(sref, params) {
var link = $state.url(sref, params);
try {
var link = $state.url(sref, params);

//NOTE: Is this correct for forms?
if (!html5) {
link = link === '' ? '#' + prefix + '/' + link : '#' + prefix + link;
//NOTE: Is this correct for forms?
if (!html5) {
link = link === '' ? '#' + prefix + '/' + link : '#' + prefix + link;
}
element.attr(attr[tag], link);
} catch (err) {
$exceptionHandler(err);
}
element.attr(attr[tag], link);
}

//TODO: Should we depricate this and use filters instead from 0.7.0?
Expand Down

Large diffs are not rendered by default.

24 changes: 14 additions & 10 deletions src/directives/jemLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
* @param {string} params Parameters for the state link.
* @param {string} activeClass Class to add when the state targeted is active.
*/
var jemLinkDirective = [<any>'$state', '$route',
function ($state, $route) {
var jemLinkDirective = [<any>'$state', '$route', '$exceptionHandler',
function ($state, $route, $exceptionHandler) {
'use strict';
return {
restrict: 'AC',
Expand All @@ -25,14 +25,18 @@ var jemLinkDirective = [<any>'$state', '$route',
activeFn = isDefined(attrs.activeClass) ? active : noop;

function apply(sref, params) {
var link = $state.url(sref, params);
//NOTE: Is this correct for forms?
if (!html5) {
link = link === ''
? '#' + prefix + '/' + link
: '#' + prefix + link;
}
element.attr(attr[tag], link);
try {
var link = $state.url(sref, params);
//NOTE: Is this correct for forms?
if (!html5) {
link = link === ''
? '#' + prefix + '/' + link
: '#' + prefix + link;
}
element.attr(attr[tag], link);
} catch (err) {
$exceptionHandler(err);
}
}

//TODO: Should we depricate this and use filters instead from 0.7.0?
Expand Down

0 comments on commit 44a97ef

Please sign in to comment.