我是新來的angular並在控制檯TypeError: name.replace is not a function
中不斷收到以下錯誤。我不確定究竟是什麼造成的,但它似乎是由ng-style
聲明造成的,也許與駝峯事件有關?Angular TypeError:name.replace不是ng風格的函數
我不明白的部分是爲什麼ng-style="isFrontView() || !matches && {'display': 'none'}"
會拋出錯誤,但ng-style="!isFrontView() || !matches && {'display': 'none'}"
不會拋出錯誤。
爲了解決這個問題,我嘗試從函數名中刪除camelCase並全部小寫。我也試圖使用!!isFrontView()
,但似乎都沒有刪除錯誤信息。
是否有人知道這個錯誤消息的原因是什麼以及可能的修復?
HTML模板:
<div class="system-view">
<div class="controller-container fill" id="systemView1" ng-style="isFrontView() || !matches && {'display': 'none'}">
<canvas id="canvasLayer-shell" data-layername="front" width="617" height="427"></canvas>
<i ng-if="!matches" class="fa fa-repeat toggle-view" ng-click="changeView()" ng-touch="changeView()"></i>
</div>
<div class="controller-container fill" id="systemView2" ng-style="!isFrontView() || !matches && {'display': 'none'}">
<canvas id="canvasLayer-shell" data-layername="back" width="617" height="427"></canvas>
<i ng-if="!matches" class="fa fa-undo toggle-view" ng-click="changeView()" ng-touch="changeView()"></i>
</div>
</div>
後端代碼:
$scope.frontView = true;
$scope.matches = true;
$scope.isFrontView = function() {
return $scope.frontView;
};
$scope.changeView = function() {
$scope.frontView = !$scope.frontView;
};
附:即使在控制檯出錯的情況下,一切仍然正常。
旁註:你爲什麼不只是使用NG式表達的NG-顯示/ NG隱藏nstead隱藏元件。 – PSL
@PSL當前應用程序設置爲同時繪製兩個畫布,所以它們必須留在DOM中。 – Steven10172
如果使用ng-show/ng-hide。他們會留在DOM中,而不像ng-if。 – PSL