AngularJS:TypeError:无法读取未定义

时间:2017-11-21 07:54:43

标签: javascript angularjs

我有一个控制器,里面有两个切换按钮,可以相应地显示视图。控制器中显示的两种类型的视图由$scope.isStore变量控制,html变量是angular.js:13424 TypeError: Cannot read property 'childNodes' of undefined at nodeLinkFn (angular.js:9017) at compositeLinkFn (angular.js:8333) at compositeLinkFn (angular.js:8336) at compositeLinkFn (angular.js:8336) at publicLinkFn (angular.js:8213) at lazyCompilation (angular.js:8551) at boundTranscludeFn (angular.js:8350) at controllersBoundTransclude (angular.js:9072) at ngIfWatchAction (angular.js:25323) at Scope.$digest (angular.js:16869) 部分中的决定因素。

但是,一旦我切换应该更改的部分变为空白,我得到以下错误。

setTimeout

我尝试寻找解决方案,但没有一个适合我。即使在更改$ scope变量时设置 <div id="go-pro" class="storeCoins" ng-if="isPremiumUser==true"> <span class="coinText">you are Premium User</span> <img class="imgPro" id="feature" ng-src="/app/app_resources/icons/pirate_girl.png" /> </div> <table id="links" class="tab-selector"> <tr> <td class="tablinks" ng-class="{highlighwallet: isStore==true}" ng-click="walletController.showStore(event)">STORE</td> <td class="tablinks" ng-class="{highlighwallet: isStore==false}" ng-click="walletController.showHistory(event)">TASK HISTORY</td> </tr> </table> <div ng-if="isStore==false"> <ul> <li class="taskList" ng-click="arbit()"> <div class="taskHistoryList" ng-repeat="taskList in mergedTransaction | orderBy:'-Date'"> <img class="taskListImage" ng-src="{{walletController.getImage(taskList)}}"> <span ng-show="isCoinBought">{{ taskList.coin_value}}</span> </div> </li> </ul> </div> <div ng-if="isStore==true"> <packgroup-directive> </packgroup-directive> <div ng-controller="WalletController"> <outfit-directive></outfit-directive> </div> <h3>GO PRO</h3> <div id="go-pro" ng-if="isPremiumUser==false"> <img class="feature" ng-click="walletController.onGoPremiumChosen()" id="feature" ng-src="/app/app_resources/language/en/resources/banner.jpg" /> </div> </div> </div> 函数也会产生相同的输出。

HTML部分:

walletModel.showStore = function () {
        console.log("ShowStore")
          $scope.isStore = true;
          $scope.$apply();
    }

JS Part:

health

完全控制器JS:https://justpaste.it/1dqxh

指令的JS:https://justpaste.it/1dqxj

1 个答案:

答案 0 :(得分:2)

您知道ng-ifng-show之间的区别吗?

ng-if的值为false时不创建元素

ng-show就像hidden一样活跃。

因此,为了解决您的问题,我认为您必须将ng-if更改为ng-show或在'.js'中进行控制