![](/img/trans.png)
[英]TypeError: Cannot read property 'childNodes' of undefined angular
[英]AngularJS : TypeError: Cannot read property 'childNodes' of undefined
我有一個控制器,里面有兩個切換按鈕來相應地顯示視圖。 控制器中顯示的兩種類型的視圖由$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)
我嘗試尋找解決方案,但沒有一個對我有用。 即使在更改 $scope 變量時設置setTimeout
函數也會給出相同的輸出。
HTML 部分:
<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>
JS部分:
walletModel.showStore = function () {
console.log("ShowStore")
$scope.isStore = true;
$scope.$apply();
}
完整的控制器 JS: https : //justpaste.it/1dqxh
JS 指令: https : //justpaste.it/1dqxj
你知道ng-if
和ng-show
之間的區別嗎?
ng-if
當元素值為 false 時不創建元素,
和ng-show
active 就像hidden
。
因此,要解決您的問題,我認為您應該將ng-if
更改為ng-show
或在 '.js' 中控制它
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.