This article describes the method of AngularJS to solve the long expression (ui-set) of ng interface. Share it for your reference, as follows:
This article comes from a question from netizen Sun Shine, and the questions are as follows:
Hello, I want to ask for a question.
My object name is written very deeply in $scope. I used the same object many times in html. Is it right to bind it to a temporary variable in html?
for example:
$ = {
'name': 'xxx',
'state': 'active'};
In the template,
{{}}
{{}}
Similar to this, can I pre-assign a temporary variable to a temporary variable, and then just do it in two spans? I think it is faster to parse this way.
But I tried it, but it didn't work. Please give me some advice.
Thanks in advance.
The first thing to be noted here is that all references to the ng interface need to be in the viewmodel of $scope (the glue layer of ui and view), so if we want to make the expression more readable and friendly, then we must create this variable on $scope.
In addition, for the bunch of $watch used by ng, we can implement dirty checks. If you understand these, then we can easily implement a set of spring.
<c:set var="xxx" expression="xxx" />
tag.
For implementing such tags, our best way is to use ng's directive to implement it, the code is as follows:
("", []) .directive("uiSet", [ function() { return { restrict: "EA", link: function(scope, elm, iAttrs) { scope.$watch(, function(val) { scope[iAttrs. var] = val; var apply = !scope.$$phase ? scope.$apply : ; apply(); }); } }; } ]);
I hope this article will be helpful to everyone's AngularJS programming.