fixed filter this

This commit is contained in:
Misko Hevery 2010-04-07 16:36:33 -07:00
parent 3d0b40fee2
commit a8aa5af413
4 changed files with 28 additions and 22 deletions

23
angular-debug.js vendored
View file

@ -3124,7 +3124,8 @@ function valueAccessor(scope, element) {
var validatorName = element.attr('ng-validate') || NOOP,
validator = compileValidator(validatorName),
required = element.attr('ng-required'),
lastError;
lastError,
invalidWidgets = scope.$invalidWidgets || {markValid:noop, markInvalid:noop};
required = required || required === '';
if (!validator) throw "Validator named '" + validatorName + "' not found.";
function validate(value) {
@ -3132,6 +3133,10 @@ function valueAccessor(scope, element) {
if (error !== lastError) {
elementError(element, NG_VALIDATION_ERROR, error);
lastError = error;
if (error)
invalidWidgets.markInvalid(element);
else
invalidWidgets.markValid(element);
}
return value;
}
@ -3339,7 +3344,6 @@ angularWidget('NG:SWITCH', function ngSwitch(element){
}
}
});
console.log(regex);
var match = on.match(new RegExp(regex));
if (match) {
foreach(params, function(name, index){
@ -3438,6 +3442,21 @@ angularService("$hover", function(browser) {
}
});
}, {inject:['$browser']});
angularService("$invalidWidgets", function(){
var invalidWidgets = [];
invalidWidgets.markValid = function(element){
var index = indexOf(invalidWidgets, element);
if (index != -1)
invalidWidgets.splice(index, 1);
};
invalidWidgets.markInvalid = function(element){
var index = indexOf(invalidWidgets, element);
if (index === -1)
invalidWidgets.push(element);
};
return invalidWidgets;
});
var browserSingleton;
angularService('$browser', function browserFactory(){
if (!browserSingleton) {

View file

@ -372,16 +372,7 @@ Parser.prototype = {
for ( var i = 0; i < argsFn.length; i++) {
args.push(argsFn[i](self));
}
var pipeThis = function(){
var _this = this;
foreach(self, function(v, k) {
if (k.charAt(0) == '$') {
_this[k] = v;
}
});
};
pipeThis.prototype = self.self;
return fn.apply(new pipeThis(), args);
return fn.apply(self.state, args);
};
return function(){
return fnInvoke;

View file

@ -27,7 +27,7 @@ function valueAccessor(scope, element) {
required = required || required === '';
if (!validator) throw "Validator named '" + validatorName + "' not found.";
function validate(value) {
var error = required && !trim(value) ? "Required" : validator({self:scope, scope:{get:scope.$get, set:scope.$set}}, value);
var error = required && !trim(value) ? "Required" : validator({state:scope, scope:{get:scope.$get, set:scope.$set}}, value);
if (error !== lastError) {
elementError(element, NG_VALIDATION_ERROR, error);
lastError = error;
@ -242,7 +242,6 @@ angularWidget('NG:SWITCH', function ngSwitch(element){
}
}
});
console.log(regex);
var match = on.match(new RegExp(regex));
if (match) {
foreach(params, function(name, index){

View file

@ -13,17 +13,14 @@ FiltersTest.prototype.XtestCurrency = function(){
assertEquals(html.hasClass('ng-format-negative'), false);
};
FiltersTest.prototype.XtestFilterThisIsContext = function(){
expectAsserts(2);
var scope = new Scope();
Scope.expressionCache = {};
scope.set('name', 'misko');
var context = {$element:123};
FiltersTest.prototype.testFilterThisIsContext = function(){
expectAsserts(1);
var scope = createScope();
scope.name = 'misko';
angular.filter.testFn = function () {
assertEquals('Context not equal', 123, this.$element);
assertEquals('scope not equal', 'misko', this.name);
};
scope.eval("0|testFn", context);
scope.$eval("0|testFn");
delete angular.filter['testFn'];
};