Skip to content

Commit 650206e

Browse files
committed
MERGE: ng:options
1 parent c3decfe commit 650206e

File tree

5 files changed

+25
-18
lines changed

5 files changed

+25
-18
lines changed

docs/angular.element.ngdoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ raw DOM references.
3232
- [data()](http://api.jquery.com/data/)
3333
- [hasClass()](http://api.jquery.com/hasClass/)
3434
- [parent()](http://api.jquery.com/parent/)
35+
- [prepend()](http://api.jquery.com/prepend/)
3536
- [remove()](http://api.jquery.com/remove/)
3637
- [removeAttr()](http://api.jquery.com/removeAttr/)
3738
- [removeClass()](http://api.jquery.com/removeClass/)

src/parser.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ function parser(text, json){
239239
pipeFunction =
240240
function (){ throwError("is not valid json", {text:text, index:0}); };
241241
}
242-
//TODO: Should'nt all of the public methods have assertAllConsumed?
243-
//TODO: I think these should be public instead of scope.$eval() being the enterenece.
242+
//TODO: Shouldn't all of the public methods have assertAllConsumed?
243+
//TODO: I think these should be public as part of the parser api instead of scope.$eval().
244244
return {
245245
assignable: assertConsumed(assignable),
246246
primary: assertConsumed(primary),
@@ -762,8 +762,7 @@ function compileExpr(expr) {
762762
return parser(expr).statements();
763763
}
764764

765-
//TODO(misko): Deprecate? Remove!
766-
// I think that compilation should be a service.
765+
//TODO(misko): Deprecate? Remove! I think that compilation should be a service.
767766
function expressionCompile(exp){
768767
if (typeof exp === $function) return exp;
769768
var fn = compileCache[exp];

src/widgets.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -541,16 +541,22 @@ angularWidget('button', inputWidgetSelector);
541541
* @name angular.directive.ng:options
542542
*
543543
* @description
544-
* Dynamically generate a list of `option`s for a `<select>` element. Normaly the 'ng:options'
545-
* directive does not require you to specify any `<option>` elements, however if you wish
546-
* to support `null` value then a special `<option value="">null selection text</option>` can be
547-
* added to the `<select>`.
544+
* Replace this whole paragraph with:
548545
*
549-
* NOTE: The normal aproach of {@link angular.widget.@ng:repeat ng:repeat} does not work here for
550-
* several reasons:
546+
* Dynamically generate a list of `<option>` elements for a `<select>` element using the array
547+
* obtained by evaluating the `ng:options` expression.
551548
*
552-
* * option requires strings, where as dynamic arrays are composed of objects.
553-
* * {@link angular.widget.@ng:repeat ng:repeat} unrolles after the select binds causing
549+
* Optionally, a single hard-coded `<option>` element, with the value set to an empty string, can
550+
* be nested into the `<select>` element. This element will then represent `null` or "not selected"
551+
* option. See example below for demonstration.
552+
*
553+
* Note: `ng:options` provides iterator facility for `<option>` element which must be used instead
554+
* of {@link angular.widget.@ng:repeat ng:repeat}. `ng:repeat` is not suitable for use with
555+
* `<option>` element because of the following reasons:
556+
*
557+
* * `option` value attribuet requires a string, where as the array we are trying to unroll is
558+
* composed of objects.
559+
* * {@link angular.widget.@ng:repeat ng:repeat} unrolls after the select binds causing
554560
* incorect rendering on most browsers.
555561
* * binding to a value not in list confuses most browsers.
556562
*
@@ -614,6 +620,7 @@ angularWidget('button', inputWidgetSelector);
614620
var NG_OPTIONS_REGEXP = /^(.*)\s+for\s+([\$\w][\$\w\d]*)\s+in\s+(.*)$/;
615621
angularWidget('select', function(element){
616622
this.descend(true);
623+
this.directives(true);
617624
var isMultiselect = element.attr('multiple');
618625
var expression = element.attr('ng:options');
619626
var match;
@@ -660,7 +667,7 @@ angularWidget('select', function(element){
660667
if (value == '?') {
661668
value = undefined;
662669
} else {
663-
value = value == '' ? null : collection[value];
670+
value = (value == '' ? null : collection[value]);
664671
}
665672
}
666673
if (value !== undefined) model.set(value);
@@ -680,6 +687,7 @@ angularWidget('select', function(element){
680687
var currentItem;
681688
var selectValue = '';
682689
var isMulti = isMultiselect;
690+
683691
if (isMulti) {
684692
selectValue = new HashMap();
685693
if (modelValue && isNumber(length = modelValue.length)) {

test/directivesSpec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,13 +289,13 @@ describe("directive", function(){
289289
}
290290
};
291291
var scope = compile('<div ng:controller="temp.Greeter"><div ng:controller="temp.ChildGreeter">{{greet("misko")}}</div></div>');
292-
scope.$apply();
293292
expect(scope.greeting).not.toBeDefined();
294293
expect(scope.greeter.greeting).toEqual('hello');
295294
expect(scope.greeter.greet('misko')).toEqual('hello misko!');
296295
expect(scope.greeter.greeting).toEqual('hello');
297296
expect(scope.childGreeter.greeting).toEqual('hey');
298297
expect(scope.childGreeter.$parent.greeting).toEqual('hello');
298+
scope.$flush();
299299
expect(scope.$element.text()).toEqual('hey dude!');
300300
});
301301

test/widgetsSpec.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -586,8 +586,8 @@ describe("widget", function(){
586586

587587
function createSelect(multiple, blank, unknown){
588588
select = jqLite(
589-
'<select' + (multiple ? ' multiple' : '') +
590-
' name="selected" ng:options="value.name for value in values">' +
589+
'<select name="selected" ' + (multiple ? ' multiple' : '') +
590+
' ng:options="value.name for value in values">' +
591591
(blank ? '<option value="">blank</option>' : '') +
592592
(unknown ? '<option value="?">unknown</option>' : '') +
593593
'</select>');
@@ -631,7 +631,7 @@ describe("widget", function(){
631631
createSingleSelect();
632632
scope.values = [];
633633
scope.$flush();
634-
expect(select.find('option').length).toEqual(1); // becouse we add special empty option
634+
expect(select.find('option').length).toEqual(1); // because we add special empty option
635635
expect(sortedHtml(select.find('option')[0])).toEqual('<option></option>');
636636

637637
scope.values.push({name:'A'});
@@ -640,7 +640,6 @@ describe("widget", function(){
640640
expect(select.find('option').length).toEqual(1);
641641
expect(sortedHtml(select.find('option')[0])).toEqual('<option value="0">A</option>');
642642

643-
644643
scope.values.push({name:'B'});
645644
scope.$flush();
646645
expect(select.find('option').length).toEqual(2);

0 commit comments

Comments
 (0)