猿问

请教关于angularJs的$watch 问题?

angular.module("exampleApp",[])
                .directive("unorderedList",function(){
                       return function(scope, element, attrs){
                           var data= scope[attrs["unorderedList"]];
                           var propertyExpression = attrs["listProperty"];
                           if(angular.isArray(data)){
                               var listElem = angular.element("<ul>");
                               element.append(listElem);
                               for(var i=0; i< data.length; i++){
                                   (function(){
                                       var itemElement =angular.element("<li>");
                                       listElem.append(itemElement);
                                       var index = i;
                                       var watcherFn = function(watchScope){
                                           return  watchScope.$eval(propertyExpression, data[index]);
                                       }
                                       scope.$watch(watcherFn, function(newValue,oldValue){
                                           itemElement.text(newValue);
                                       });
                                   }())
                               }
                           }
                       }
                })

请问上述代码的执行过程具体是怎么执行的?

嘛也不会
浏览 1747回答 0
0回答
随时随地看视频慕课网APP
我要回答