Skip to content

Commit 03f8425

Browse files
committed
Flag filters with $stateful=true for compatibility reasons with angular-1.3.0-rc.3
Closes #68
1 parent fa5388e commit 03f8425

File tree

5 files changed

+44
-18
lines changed

5 files changed

+44
-18
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Or use this CDN link (thanks to [cdnjs.com](http://cdnjs.com)):
2121
<script src="//cdnjs.cloudflare.com/ajax/libs/angular-route-segment/1.3.0/angular-route-segment.min.js"></script>
2222
```
2323

24-
Tested with AngularJS 1.1.5, 1.2.21 and 1.3.0-beta.17.
24+
Tested with AngularJS 1.1.5, 1.2.21 and 1.3.0-rc.3.
2525

2626
Overview
2727
--------

example/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@
3939
</div>
4040

4141

42-
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.17/angular.js"></script>
43-
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.17/angular-route.js"></script>
44-
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.17/angular-animate.js"></script>
42+
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.3/angular.js"></script>
43+
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.3/angular-route.js"></script>
44+
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.3/angular-animate.js"></script>
4545
<script src="../build/angular-route-segment.min.js"></script>
4646
<script src="app.js"></script>
4747

karma-angular-1.3.conf.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ module.exports = function(config) {
88
files: [
99
'test/lib/jquery.min.js',
1010
'test/lib/helpers.js',
11-
'https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.17/angular.js',
12-
'https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.17/angular-route.js',
13-
'https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.17/angular-animate.js',
14-
'https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.17/angular-mocks.js',
11+
'https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.3/angular.js',
12+
'https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.3/angular-route.js',
13+
'https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.3/angular-animate.js',
14+
'https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.3/angular-mocks.js',
1515
'src/**/*.js',
1616
'test/unit/**/*.js'
1717
],

src/route-segment.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -492,49 +492,59 @@ mod.provider( '$routeSegment',
492492
* <a ng-href="{{ 'index.list.itemInfo' | routeSegmentUrl: {id: 123} }}">
493493
*/
494494
mod.filter('routeSegmentUrl', ['$routeSegment', function($routeSegment) {
495-
return function(segmentName, params) {
495+
var filter = function(segmentName, params) {
496496
return $routeSegment.getSegmentUrl(segmentName, params);
497-
}
497+
};
498+
filter.$stateful = true;
499+
return filter;
498500
}]);
499501

500502
/**
501503
* Usage:
502504
* <li ng-class="{active: ('index.list' | routeSegmentEqualsTo)}">
503505
*/
504506
mod.filter('routeSegmentEqualsTo', ['$routeSegment', function($routeSegment) {
505-
return function(value) {
507+
var filter = function(value) {
506508
return $routeSegment.name == value;
507-
}
509+
};
510+
filter.$stateful = true;
511+
return filter;
508512
}]);
509513

510514
/**
511515
* Usage:
512516
* <li ng-class="{active: ('section1' | routeSegmentStartsWith)}">
513517
*/
514518
mod.filter('routeSegmentStartsWith', ['$routeSegment', function($routeSegment) {
515-
return function(value) {
519+
var filter = function(value) {
516520
return $routeSegment.startsWith(value);
517-
}
521+
};
522+
filter.$stateful = true;
523+
return filter;
518524
}]);
519525

520526
/**
521527
* Usage:
522528
* <li ng-class="{active: ('itemInfo' | routeSegmentContains)}">
523529
*/
524530
mod.filter('routeSegmentContains', ['$routeSegment', function($routeSegment) {
525-
return function(value) {
531+
var filter = function(value) {
526532
return $routeSegment.contains(value);
527-
}
533+
};
534+
filter.$stateful = true;
535+
return filter;
528536
}]);
529537

530538
/**
531539
* Usage:
532540
* <li ng-class="{active: ('index.list.itemInfo' | routeSegmentEqualsTo) && ('id' | routeSegmentParam) == 123}">
533541
*/
534542
mod.filter('routeSegmentParam', ['$routeSegment', function($routeSegment) {
535-
return function(value) {
543+
var filter = function(value) {
536544
return $routeSegment.$routeParams[value];
537-
}
545+
};
546+
filter.$stateful = true;
547+
return filter;
538548
}]);
539549

540550

test/unit/route-segment.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,5 +985,21 @@ describe('route segment', function() {
985985
$routeSegment.$routeParams.qux = 'quux';
986986
expect($filter('routeSegmentParam')('qux')).toBe('quux');
987987
}))
988+
989+
it('should expect the filters to be stateful and not cached', inject(function($compile, $routeSegment, $rootScope) {
990+
var elm = $('<div>{{"qux" | routeSegmentParam}}</div>'),
991+
scope = $rootScope.$new();
992+
993+
$routeSegment.$routeParams.qux = 'quux';
994+
$compile(elm)(scope);
995+
scope.$apply();
996+
997+
expect(elm.text()).toBe('quux');
998+
999+
$routeSegment.$routeParams.qux = 'changed';
1000+
scope.$apply();
1001+
1002+
expect(elm.text()).toBe('changed');
1003+
}))
9881004
})
9891005
})

0 commit comments

Comments
 (0)