angularjs – Angular TypeError:name.replace不是ng-style的函
发布时间:2020-12-17 07:32:54 所属栏目:安全 来源:网络整理
导读:我是角色的新手并且在控制台TypeError中不断收到以下错误:name.replace不是函数.我不确定究竟是什么导致它,但它似乎是由ng风格的声明引起的,也许与camelCase有关? 我不明白的部分是为什么ng-style =“isFrontView()||!匹配 {‘display’:’none’}”抛出
我是角色的新手并且在控制台TypeError中不断收到以下错误:name.replace不是函数.我不确定究竟是什么导致它,但它似乎是由ng风格的声明引起的,也许与camelCase有关?
我不明白的部分是为什么ng-style =“isFrontView()||!匹配&& {‘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-style的使用不正确.
ng-style sets a watcher on the expression并设置
element’s style with the help of jquery/jqlite element.css .并且inside element.css css属性(name)被转换为标准的驼峰套管(
which uses regex string replace).在您的特定情况下,表达式求值为boolean(true)而不是对象(
ng-style does this for each property),boolean没有replace属性(在字符串对象上可用),因此失败.您可以通过使用字符串连接将表达式转换为求值来测试此值.
即ng-style =“”(isFrontView()||!匹配&& {‘display’:’none’})” 查看表达式所有你需要它来隐藏和显示元素,你可以使用 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |