Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit a8aa5af

Browse files
author
Misko Hevery
committed
fixed filter this
1 parent 3d0b40f commit a8aa5af

File tree

4 files changed

+28
-22
lines changed

4 files changed

+28
-22
lines changed

angular-debug.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3124,14 +3124,19 @@ function valueAccessor(scope, element) {
31243124
var validatorName = element.attr('ng-validate') || NOOP,
31253125
validator = compileValidator(validatorName),
31263126
required = element.attr('ng-required'),
3127-
lastError;
3127+
lastError,
3128+
invalidWidgets = scope.$invalidWidgets || {markValid:noop, markInvalid:noop};
31283129
required = required || required === '';
31293130
if (!validator) throw "Validator named '" + validatorName + "' not found.";
31303131
function validate(value) {
31313132
var error = required && !trim(value) ? "Required" : validator({self:scope, scope:{get:scope.$get, set:scope.$set}}, value);
31323133
if (error !== lastError) {
31333134
elementError(element, NG_VALIDATION_ERROR, error);
31343135
lastError = error;
3136+
if (error)
3137+
invalidWidgets.markInvalid(element);
3138+
else
3139+
invalidWidgets.markValid(element);
31353140
}
31363141
return value;
31373142
}
@@ -3339,7 +3344,6 @@ angularWidget('NG:SWITCH', function ngSwitch(element){
33393344
}
33403345
}
33413346
});
3342-
console.log(regex);
33433347
var match = on.match(new RegExp(regex));
33443348
if (match) {
33453349
foreach(params, function(name, index){
@@ -3438,6 +3442,21 @@ angularService("$hover", function(browser) {
34383442
}
34393443
});
34403444
}, {inject:['$browser']});
3445+
3446+
angularService("$invalidWidgets", function(){
3447+
var invalidWidgets = [];
3448+
invalidWidgets.markValid = function(element){
3449+
var index = indexOf(invalidWidgets, element);
3450+
if (index != -1)
3451+
invalidWidgets.splice(index, 1);
3452+
};
3453+
invalidWidgets.markInvalid = function(element){
3454+
var index = indexOf(invalidWidgets, element);
3455+
if (index === -1)
3456+
invalidWidgets.push(element);
3457+
};
3458+
return invalidWidgets;
3459+
});
34413460
var browserSingleton;
34423461
angularService('$browser', function browserFactory(){
34433462
if (!browserSingleton) {

src/Parser.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -372,16 +372,7 @@ Parser.prototype = {
372372
for ( var i = 0; i < argsFn.length; i++) {
373373
args.push(argsFn[i](self));
374374
}
375-
var pipeThis = function(){
376-
var _this = this;
377-
foreach(self, function(v, k) {
378-
if (k.charAt(0) == '$') {
379-
_this[k] = v;
380-
}
381-
});
382-
};
383-
pipeThis.prototype = self.self;
384-
return fn.apply(new pipeThis(), args);
375+
return fn.apply(self.state, args);
385376
};
386377
return function(){
387378
return fnInvoke;

src/widgets.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function valueAccessor(scope, element) {
2727
required = required || required === '';
2828
if (!validator) throw "Validator named '" + validatorName + "' not found.";
2929
function validate(value) {
30-
var error = required && !trim(value) ? "Required" : validator({self:scope, scope:{get:scope.$get, set:scope.$set}}, value);
30+
var error = required && !trim(value) ? "Required" : validator({state:scope, scope:{get:scope.$get, set:scope.$set}}, value);
3131
if (error !== lastError) {
3232
elementError(element, NG_VALIDATION_ERROR, error);
3333
lastError = error;
@@ -242,7 +242,6 @@ angularWidget('NG:SWITCH', function ngSwitch(element){
242242
}
243243
}
244244
});
245-
console.log(regex);
246245
var match = on.match(new RegExp(regex));
247246
if (match) {
248247
foreach(params, function(name, index){

test/FiltersTest.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,14 @@ FiltersTest.prototype.XtestCurrency = function(){
1313
assertEquals(html.hasClass('ng-format-negative'), false);
1414
};
1515

16-
FiltersTest.prototype.XtestFilterThisIsContext = function(){
17-
expectAsserts(2);
18-
var scope = new Scope();
19-
Scope.expressionCache = {};
20-
scope.set('name', 'misko');
21-
var context = {$element:123};
16+
FiltersTest.prototype.testFilterThisIsContext = function(){
17+
expectAsserts(1);
18+
var scope = createScope();
19+
scope.name = 'misko';
2220
angular.filter.testFn = function () {
23-
assertEquals('Context not equal', 123, this.$element);
2421
assertEquals('scope not equal', 'misko', this.name);
2522
};
26-
scope.eval("0|testFn", context);
23+
scope.$eval("0|testFn");
2724
delete angular.filter['testFn'];
2825
};
2926

0 commit comments

Comments
 (0)