scope.lastLessOne有趣的事情

时间:2015-12-10 09:40:37

标签: javascript angularjs

这个AngularJS代码非常完美:

scope.last = {name:null, list:[]};
        scope.llOne = {name:null, list:[]};
        scope.first = {name:null, list: []};
        scope.listNodes = [];

        //Eventos vista
        scope.expandNode = function (node){

            if ((!scope.last.name) && (!scope.llOne.name) && (!scope.first.name)){
                scope.llOne.name = node.column0;
                scope.llOne.list = scope.listNodes;
            } else if ((!scope.last.name) && (!scope.first.name)){
                scope.last.name = node.column0;
                scope.last.list = scope.listNodes;
            } else if (!scope.first.name) {
                scope.first.name = scope.llOne.name;
                scope.first.list = scope.llOne.list;
                scope.llOne.name = scope.last.name;
                scope.llOne.list = scope.last.list;
                scope.last.name = node.column0; 
                scope.last.list = scope.listNodes;
            } else {
                scope.llOne.name = scope.last.name;
                scope.llOne.list = scope.last.list;
                scope.last.name = node.column0; 
                scope.last.list = scope.listNodes;
            }

            busquedaDireccionService.expandNode(node).then(function (data){
                scope.listNodes = data;
            }, function (error) {
                var properties = $injector.get(profile);
                $state.go(properties.errorState,{msg:'ERROR_SRV_CALLEJERO'});
                throw error;
            });
        };

但是这个没有:

scope.last = {name:null, list:[]};
        scope.lastLessOne = {name:null, list:[]};
        scope.first = {name:null, list: []};
        scope.listNodes = [];

        //Eventos vista
        scope.expandNode = function (node){

            if ((!scope.last.name) && (!scope.lastLessOne.name) && (!scope.first.name)){
                scope.lastLessOne.name = node.column0;
                scope.lastLessOne.list = scope.listNodes;
            } else if ((!scope.last.name) && (!scope.first.name)){
                scope.last.name = node.column0;
                scope.last.list = scope.listNodes;
            } else if (!scope.first.name) {
                scope.first.name = scope.lastLessOne.name;
                scope.first.list = scope.lastLessOne.list;
                scope.llOne.name = scope.last.name;
                scope.llOne.list = scope.last.list;
                scope.last.name = node.column0; 
                scope.last.list = scope.listNodes;
            } else {
                scope.lastLessOne.name = scope.last.name;
                scope.lastLessOne.list = scope.last.list;
                scope.last.name = node.column0; 
                scope.last.list = scope.listNodes;
            }

            busquedaDireccionService.expandNode(node).then(function (data){
                scope.listNodes = data;
            }, function (error) {
                var properties = $injector.get(profile);
                $state.go(properties.errorState,{msg:'ERROR_SRV_CALLEJERO'});
                throw error;
            });
        };

这很有趣但是,如果我使用一个名为" lastLessOne"的变量。在控制器的范围内,在视图中,变量的值始终为undefined。如果改变变量的名称,一切似乎都没问题。

有人为什么?

1 个答案:

答案 0 :(得分:0)

两个代码都正常工作。您的代码中应该存在其他一些错误。

参见lastLessOne JSFiddle

的演示

参见llOne JSFiddle

的演示
<div ng-app>
  <div ng-controller="TodoCtrl">
    {{lastLessOne}}
  </div>
</div>