mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-04-08 17:11:02 +00:00
Merge branch 'master' of github.com:angular/angular.js
This commit is contained in:
commit
d523ab61d4
3 changed files with 39 additions and 6 deletions
|
|
@ -379,7 +379,8 @@ function toKeyValue(obj) {
|
||||||
function angularInit(config){
|
function angularInit(config){
|
||||||
if (config.autobind) {
|
if (config.autobind) {
|
||||||
var scope = compile(window.document, null, {'$config':config});
|
var scope = compile(window.document, null, {'$config':config});
|
||||||
scope.$browser.addCss('../css/angular.css');
|
// TODO default to the source of angular.js
|
||||||
|
scope.$browser.addCss('css/angular.css');
|
||||||
scope.$init();
|
scope.$init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ function modelAccessor(scope, element) {
|
||||||
},
|
},
|
||||||
set: function(value) {
|
set: function(value) {
|
||||||
if (value !== undefined) {
|
if (value !== undefined) {
|
||||||
scope.$tryEval(expr + '=' + toJson(value), element);
|
return scope.$tryEval(expr + '=' + toJson(value), element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -37,7 +37,9 @@ function valueAccessor(scope, element) {
|
||||||
if (lastError)
|
if (lastError)
|
||||||
elementError(element, NG_VALIDATION_ERROR, null);
|
elementError(element, NG_VALIDATION_ERROR, null);
|
||||||
try {
|
try {
|
||||||
return parse(element.val());
|
var value = parse(element.val());
|
||||||
|
validate();
|
||||||
|
return value;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
lastError = e;
|
lastError = e;
|
||||||
elementError(element, NG_VALIDATION_ERROR, e);
|
elementError(element, NG_VALIDATION_ERROR, e);
|
||||||
|
|
@ -163,13 +165,15 @@ function inputWidget(events, modelAccessor, viewAccessor, initFn) {
|
||||||
var scope = this,
|
var scope = this,
|
||||||
model = modelAccessor(scope, element),
|
model = modelAccessor(scope, element),
|
||||||
view = viewAccessor(scope, element),
|
view = viewAccessor(scope, element),
|
||||||
action = element.attr('ng-change') || '';
|
action = element.attr('ng-change') || '',
|
||||||
|
lastValue;
|
||||||
initFn.call(scope, model, view, element);
|
initFn.call(scope, model, view, element);
|
||||||
this.$eval(element.attr('ng-init')||'');
|
this.$eval(element.attr('ng-init')||'');
|
||||||
// Don't register a handler if we are a button (noopAccessor) and there is no action
|
// Don't register a handler if we are a button (noopAccessor) and there is no action
|
||||||
if (action || modelAccessor !== noopAccessor) {
|
if (action || modelAccessor !== noopAccessor) {
|
||||||
element.bind(events, function(){
|
element.bind(events, function(){
|
||||||
model.set(view.get());
|
model.set(view.get());
|
||||||
|
lastValue = model.get();
|
||||||
scope.$tryEval(action, element);
|
scope.$tryEval(action, element);
|
||||||
scope.$root.$eval();
|
scope.$root.$eval();
|
||||||
// if we have noop initFn than we are just a button,
|
// if we have noop initFn than we are just a button,
|
||||||
|
|
@ -177,8 +181,12 @@ function inputWidget(events, modelAccessor, viewAccessor, initFn) {
|
||||||
return initFn != noop;
|
return initFn != noop;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
view.set(model.get());
|
view.set(lastValue = model.get());
|
||||||
scope.$watch(model.get, view.set);
|
scope.$watch(model.get, function(value){
|
||||||
|
if (lastValue !== value) {
|
||||||
|
view.set(lastValue = value);
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -90,6 +90,30 @@ describe("widget", function(){
|
||||||
expect(scope.$element.val()).toEqual('456');
|
expect(scope.$element.val()).toEqual('456');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should not clober text if model changes doe to itself", function(){
|
||||||
|
compile('<input type="text" name="list" ng-format="list" value="a"/>');
|
||||||
|
|
||||||
|
scope.$element.val('a ');
|
||||||
|
scope.$element.trigger('change');
|
||||||
|
expect(scope.$element.val()).toEqual('a ');
|
||||||
|
expect(scope.list).toEqual(['a']);
|
||||||
|
|
||||||
|
scope.$element.val('a ,');
|
||||||
|
scope.$element.trigger('change');
|
||||||
|
expect(scope.$element.val()).toEqual('a ,');
|
||||||
|
expect(scope.list).toEqual(['a']);
|
||||||
|
|
||||||
|
scope.$element.val('a , ');
|
||||||
|
scope.$element.trigger('change');
|
||||||
|
expect(scope.$element.val()).toEqual('a , ');
|
||||||
|
expect(scope.list).toEqual(['a']);
|
||||||
|
|
||||||
|
scope.$element.val('a , b');
|
||||||
|
scope.$element.trigger('change');
|
||||||
|
expect(scope.$element.val()).toEqual('a , b');
|
||||||
|
expect(scope.list).toEqual(['a', 'b']);
|
||||||
|
});
|
||||||
|
|
||||||
it("should come up blank when no value specifiend", function(){
|
it("should come up blank when no value specifiend", function(){
|
||||||
compile('<input type="text" name="age" ng-format="number"/>');
|
compile('<input type="text" name="age" ng-format="number"/>');
|
||||||
scope.$eval();
|
scope.$eval();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue