This paper illustrates the method of Angularjs to solve Ng interface long expression (ui-set). Share to everyone for your reference, specific as follows:
This article comes from the Netizen sun shine Question, the question is as follows:
Hello, I'd like to ask a question.
My object name is particularly deep in $scope, and I have used the same object more than once in HTML, is it binding to a temporary variable in HTML?
Like what:
$scope. this.is.a.very.deep.obj = {
' name ': ' xxx ',
' State ': ' Active '};
In the template,
{{This.is.a.very.deep.obj.name}}}
{{this.is.a.very.deep.obj.state}}}
Like this, can I assign this.is.a.very.deep.obj to a temporary variable and then just o.name in two spans, o.state? I think it's quicker to parse it out.
But I tried it, and it didn't work. Ask for advice.
Thanks for the first.
The first thing to note here is that all references to the NG interface need to be in $scope this ViewModel (UI and view glue layer), so if we want to be able to make the expression more readable and friendlier, then we have to create this variable on the $scope.
And then for Ng's use of a bunch of $watch, to implement a dirty check, if you understand this, then we can easily implement a set of like spring
<c:set var= "xxx" expression= "xxx"/>
The tag.
The best way to implement this kind of tag is to use NG's directive to implement the code as follows:
Angular.module ("Greengerong.ui.tag", [])
. Directive ("Uiset", [
function () {return
{
restrict: "EA" ,
link:function (Scope, elm, iattrs) {
scope. $watch (Iattrs.expression, function (val) {
scope[iattrs.
var] = val;
var apply =!scope.$ $phase? Scope. $apply: Angular.noop;
Apply ();
});
}
};
I hope this article will help you to Angularjs program design.