Many thanks to @NevilleS and @jbedard for collaborating with me on a solution to this!
Closes#9394Closes#9865
BREAKING CHANGE: previously, ngModel invoked getter/setters in the global context.
For example:
```js
<input ng-model="model.value" ng-model-options="{ getterSetter: true }">
```
would previously invoke `model.value()` in the global context.
Now, ngModel invokes `value` with `model` as the context.
It's unlikely that real apps relied on this behavior. If they did they can use `.bind` to explicilty
bind a getter/getter to the global context, or just reference globals normally without `this`.
Currently, providing '' to $location#url will only reset the hash, but otherwise has no effect. This
change brings the behaviour of $location#url more inline with window.location.href, which when
assigned to an empty string loads the page's base href.
Before:
$location.url() // http://www.example.com/path
$location.url('') // http://www.example.com/path
After:
$location.url() // http://www.example.com/path
$location.url('') // http://www.example.comFixes#10063Closes#10064
Previously, setting the maxlength to a negative number, would make all
input values invalid (since their length should be less than maxlength,
which is impossible).
This commit changes the behaviour of maxlength/ngMaxlength, effectively
disabling the maxlength validation (always returning true) when maxlength
is set to a negative number. This is more inline to how the HTML5
`maxlength` attribute works (both in browsers and according to the spec:
http://dev.w3.org/html5/spec-preview/attributes-common-to-form-controls.html#attr-fe-maxlength).
Related to #9874Closes#9995
Previously, when (automatically) redirecting from path that fetured a
trailing slash and optional or "eager" parameters, the resulting path
would (incorrectly) contain the special characters (`?`,`*`) along with
the parameter values.
Closes#9819Closes#9827
- extract existing functionality to public method: $setDirty
- add tests to corresponding changes
- refactor code to use extracted method
Closes#10038Closes#10049
Previously, $validate would execute the parsers to obtain a
modelValue for validation. This was necessary, because a validator
that is called outside of model / view update (e.g. from an observer)
otherwise might only an undefined modelValue, because a previous
view update has found a validation $error and set the model
to undefined (as is tradition in angular)
This is problematic as validators that are run immediately after
the ngModelController initializes would parse the modelValue
and replace the model, even though there had been no user input.
The solution is to go back to an older design: the ngModelController
will now internally record the $$rawModelValue. This means a model
or view update will store the set / parsed modelValue regardless
of validity, that is, it will never set it to undefined because of
validation errors.
When $validate is called, the $$rawModelValue will passed to the
validators. If the validity has changed, the usual behavior is kept:
if it became invalid, set the model to undefined, if valid,
restore the last available modelValue - the $$rawModelValue.
Additionally, $validate will only update the model when the validity
changed. This is to prevent setting initially invalid models other
than undefined to undefined (see #9063)
Fixes: #9063Fixes: #9959Fixes: #9996Fixes: #10025Closes: #9890Closes: #9913Closes: #9997Closes: #10048
Use the new private function `stringify` to convert scope values to strings,
since this can cope with cyclic references and other oddities.
Closes#10085
Fix the JSON stringification to output a more meaningful string when an
object cannot be normally converted to a JSON string, such as when the
object contains cyclic references that would cause `JSON.stringify()`
to throw an error.
Closes#10085
Only changing the `<option>` text value is not enough to trigger a render
change in IE. We need to explicit update the `label` property too.
Closes#9621Closes#10042
When using `$parse` with a stateful interceptor and the expression
is `undefined`, then return the result from the interceptor
NOTE from Igor: this is not the best solution. We need to refactor
this and one-time + $interpolate code to properly fix this. @caitp
is on it. See discussion in the PR.
Closes#9821Closes#9825
By including the `ngAria` module, `ngMessages` will automatically include the aria-live
attribute with an assertive voice, allowing validation messages to be spoken throuhg a
screenreader.
Closes#9834
The `$compile` public API documentation indicates that
a transclude function may be passed as a second parameter, but
it was not clear that this is **not** the same function that is given
to directive link functions as the `transcludeFn` parameter.
We would like to be able to pass in a transclude function the public
linking function that is returned from `$compile` if we wish to, for
example, use lazy compilation inside a directive.
Doing so, however, highlighted two bugs:
* First, the transclude function would get rebound, incorrectly, changing
its scope from its original binding.
* Second, the `containingScope` would not be updated and the wrong
`$parent` would be assigned to the `transcludedScope` resulting in a
memory leak.
This patch fixes both of these issues.
It also converts various private optional positional parameters on `publicLinkFn`
into an `options` parameter, which is an object hash. The new `options`
parameter is documented as part of the public API.
Thanks to @lgalfaso, @tbosch, and @petebacondarwin.
Closes#9413
When writing tests it's often useful to check the number of child scopes
or watchers within the current current scope subtree. Common use-case for advanced
directives is to test that the directive is properly cleaning up after itself. These
new methods simplify writing assertions that verify that child scopes were properly
destroyed or that watchers were deregistered.
Closes#9926Closes#9871
Changes:
- add rule requireSpaceBeforeBlockStatements (require space before brace when opening block statement)
- add operators to rule disallowSpaceAfterPrefixUnaryOperators (no space after prefix inc/dec ops)
- add rule disallowSpaceBeforePostfixUnaryOperators (no space before postfix inc/dec ops)
- add rule disallowSpacesInsideArrayBrackets (array literals no longer padded with spaces)
- add rule requireCommaBeforeLineBreak (line can't start with comma token)
- add rule validateLineBreaks (require LF linebreaks)
Closes#9792
Fixes a regression where the option/select values would always be set to
the key or index of a value within the corresponding collection. Prior to
some 1.3.0 refactoring, the result of the track expression would be bound
to the value, but this behavior was not documented or explicitly tested. A
cache was added in order to improve performance getting the associated
value for a given track expression.
This commit adds one explicit test for this behavior, and changes several
other trackBy tests to reflect the desired behavior as well.
Closes#9718Fixes#9592
Currently, `undefined` is returned. However, the desired behavior is to
return `null` when the controller is optional and not found.
(If this breaks your app, it really shouldn't .v.)
Closes#9404Closes#9392
The directive property `require` allows optional requirement via
the `?` before or after the `^` operator. Add tests to ensure this
functionality is not lost inadvertently.
Closes#9391Closes#9392