Angularjs   发布时间:2022-04-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了angularjs – Angular TypeError:name.replace不是ng-style的函数大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我是角色的新手并且在控制台TypeError中不断收到以下错误:name.replace不是函数.我不确定究竟是什么导致它,但它似乎是由ng风格的声明引起的,也许与camelCase有关? @H_262_1@我不明白的部分是为什么ng-style =“isFrontView()||!匹配&& {‘display’:’none’}”抛出错误,但ng-style =“!isFrontView()| |!matches&& {‘display’:’none’}“不会抛出错误.

@H_262_1@为了解决这种情况,我尝试从函数名中删除camelCase并全部小写.我也尝试使用!! isFrontView(),但似乎都没有删除错误消息.

@H_262_1@有谁知道这个错误消息的原因和潜在的修复?

@H_262_1@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>
@H_262_1@后端代码

$scope.frontView = true;
$scope.matches = true;

$scope.isFrontView = function() {
   return $scope.frontView;
};

$scope.changeView = function() {
    $scope.frontView = !$scope.frontView;
};
@H_262_1@附:即使控制台出错,一切仍然正常.

您的潜在问题是由于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属性(在字符串对象上可用),因此失败.您可以通过使用字符串连接将表达式转换为求值来测试此值. @H_262_1@即ng-style =“”(isFrontView()||!匹配&& {‘display’:’none’})”

@H_262_1@查看表达式所有你需要它来隐藏和显示元素,你可以使用ng-show/ng-hide指令来实现这一点.

大佬总结

以上是大佬教程为你收集整理的angularjs – Angular TypeError:name.replace不是ng-style的函数全部内容,希望文章能够帮你解决angularjs – Angular TypeError:name.replace不是ng-style的函数所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。