Angular.copy () deep copy
Angular provides a api--copy (source,destination) that can replicate objects, which performs a deep copy of the source object.
The following points need to be noted when using:
- Returns a Copy object if there is only one parameter (an object with no specified copy)
- If destination is specified, the deep copy object is copied to the destination
- If source is null or undefined, the source is returned directly
- If source is desitination, then it will be an error.
Angular.equals () Compare objects
The Angular.equals () method in Angularjs is used to compare the equality of two objects, values, or expressions. The principle of comparing the Equals method in a Angularjs document is described in this way:
(1) The comparison of two objects or values can be expressed through the = = =. = = = requires two values not only the same value, the same type, that is, 1 = = = "1" is not true.
(2) The two objects or values that are compared are of the same type, and all of their properties are judged equal by the Angular.equals () method.
(3) Two values are (NaN). (I think Nan = = Nan is false in JavaScript)
(4) Two values represent an expression that is literally equal, such as two regular expressions:/abc/is equal to/abc/.
Angular $apply ()
$apply method of propagating model changes.
So when exactly do we need to call the Apply () method? The situation is very small, in fact almost all of our code is wrapped in scope.apply (), like Ng?click,controller initialization, HTTP callback function, etc. In these cases, we do not need to call ourselves, in fact, we can not invoke, otherwise in the Apply () method calls the Apply () method will throw an error. We need to wrap the code in scope.apply () if we need to run the code in a new execution sequence, and we need to use it only when the new execution sequence is not created by the method of the angular JS library.
That's what I understand. The function is used to update the value of the view, which needs to be called when the view values need to be changed. Typically, this function is called by the DOM's event handler function.
For example, an input directive invokes $setviewvalue when its input is changed, such as: The Select control also calls this function to Update view value when an option is selected .
It is called when the view needs to be updated. Instructions that use Ng-model should implement this method on their own.
This method is used to determine whether the input value is empty.
For example, a directive that uses ngmodelcontroller requires that the method be used when it is necessary to determine if there are any input values. This method can be used to determine whether the value is undefined, ', null, or Nan.
You can reload the method to suit your needs.
- $setValidity (Validationerrorkey, isValid);
This method is used to change the validation status and to notify the table when the validation criteria for changes are controlled.
This method should be called by a validator. For example, a parser or a format function.
This method is used to set control to the original state.
The method can remove the ' Ng-dirty ' class and restore control to its original state (' Ng-pristine ' Class).
This method is used to cancel an update and reset the value of the INPUT element to prevent $viewcalue from occurring, which is raised by a pending debounced event or because the input box waits for some future event.
This method is used in order to change the value of the Ng-model binding in the directive, for directives that use independent scopes (which cannot be assigned by scope without a bidirectional binding attribute ).
Angularjs's Notes