【问题标题】:angular binding failing on Chrome but not Firefox or IE角度绑定在 Chrome 上失败,但在 Firefox 或 IE 上失败
【发布时间】:2014-08-14 23:18:45
【问题描述】:

Angular JS 在 IE11 和 FireFox 中完美绑定,没有错误。但在 Chrome 中,仍然没有错误,UI 控件中的绑定失败,但在平面文本转储中,它呈现正常。

火狐 IE11 Safari 虽然我没有图片,但绑定也可以在 Safari 中使用。

我怀疑这一定是脚本冲突,但我似乎找不到。 这是我正在加载的脚本,按加载顺序排列。

  1. jquery-{version}.js
  2. jquery-ui-{version}.js
  3. Common.js //JavaScript 数组的 IE 8 和 9 兼容性原型
  4. moment.js
  5. moment-timezone.js
  6. toastr.js
  7. angular.js
  8. angular-route.js
  9. angular-resource.js
  10. 角递归.js
  11. angular-loader.js
  12. angular-animate.js
  13. angular-cookies.js
  14. angular-sanitize.js
  15. angular-scenario.js
  16. angular-touch.js
  17. angular-draganddrop.js
  18. ui-bootstrap.js
  19. ui-bootstrap-tpls.js
  20. ui-utils.js
  21. ui-utils-ieshiv.js
  22. textAngular.js
  23. textAngular-sanitize.js
  24. app.js //我的代码
  25. textAngularSettings.js /我的设置

我的这个控件的数据结构是:

task.details {
    buttonLabel:false,
    correctiveActionSection:true,
    correctiveActionTitle:"Corr Title",
    correctiveLabel:"Corr Lbl",
    deficiencyLabel:"Def Lbl",
    inspect:true,
    inspectionFailedLabel:"Insp Fail",
    inspectionPassedLabel:"Insp Pass",
    inspectionTitle:"Ins Title",
    inspectionUntestedLabel:"Inspect Untest",
    instance:[],
    notCleanedLabel:"Cleaned",
    noWorkLabel:"No Work",
    recleanedLabel:"Recleaned",
    role:{},
    showCorrectiveText:true,
    showDeficiencyText:true,
    sop:{},
    suppression:{},
    items:[
            {name:"a"},
            {name:"aa"},
            {name:"aaa", causeException:true},
            {name:"aaaa", causeException:true},
            {name:"aaaaa", causeException:true}
    ],
    inspection:{
            untested:"Inspect Untest",
            passed:"Insp Pass",
            failed:"Insp Fail"}} 

我的绑定看起来像

<label class="btn btn-default"
       ng-click="InspectClick('TestKey1', false)">
    {{task.details.inspection.untested}}
    <input type="radio" ng-checked="testKey1"
           ng-disabled="!testDisable1" />
</label>

控制器:

(function () {
    'use strict';

    var controllerId = 'PreOpCtrl';

    angular.module('app').controller(controllerId,
        ['$scope', buildPreOpCtrl]);

    function buildPreOpCtrl($scope) {

        //task already exists, this is known because of this working on all other browsers.
        $scope.task.details = processDetails($scope.sourceData);
        $scope.InspectClick = InspectClick(svalue, bvalue);
    }

    function processDetails(details) {
        var ret = details;

        //Convert stringify to objects
        var i = ret.items;
        var t = JSON.parse(i);
        delete ret.items;   
        ret.items = t;

        //correct bools
        ret.showDeficiencyText = ret.showDeficiencyText === 'True' ? true : false;
        ret.showCorrectiveText = ret.showCorrectiveText === 'True' ? true : false;
        ret.correctiveActionSection = ret.correctiveActionSection === 'True' ? true : false;

        //breakdown for marshal at later time.
        ret.inspection = {
            untested: ret.inspectionUntestedLabel,
            passed: ret.inspectionPassedLabel,
            failed: ret.inspectionFailedLabel,
        };

        return ret;
    }

    //stub code. real code isn't written yet.
    function setInspectionException($scope)
    {
        return function (sval, bval) {
           console.log(sval,bval);
        };
    };

})();

没有自定义指令。没有花哨的代码。我竭尽全力让这件事尽可能简单。

更新:我已尝试将所有 ngIf 指令更改为 ngShow。页面变慢了,但问题没有解决。

【问题讨论】:

  • 想在小提琴中重现?或者至少向我们展示代码。
  • @RahilWazir 这就是问题所在。真的没有太多代码。在基本控制器上,我将任务结构绑定到范围,标签看起来像我的示例。由于这只影响Chrome,而且我有deadline,发布后,如果没有解决,我会做一个plunker demo。
  • @RahilWazir,我刚刚意识到控制器没有太多代码,所以我刚刚发布了它。 $scope.sourceData 会被填充,因为在通过控制器对其进行按摩后,带有“调试”水印的区域会被它填充。我不得不清理一些代码,所以这里可能会出现拼写错误。
  • @RahilWazir,我在 Chrome 中注意到一件事,那就是我必须经过几层 $parent 才能找到包含任务根的实际对象。即Task存在于$scope中,并且在这个controller中添加了detail。

标签: javascript angularjs internet-explorer google-chrome firefox


【解决方案1】:

我相信这个问题已经通过更新版本的 Angular 得到解决。我没有更改我的代码,更新到最新版本,问题就消失了。

我仍然不知道是什么原因造成的。

【讨论】:

    猜你喜欢
    • 2013-09-09
    • 1970-01-01
    • 2015-07-31
    • 1970-01-01
    • 2016-10-14
    • 1970-01-01
    • 1970-01-01
    • 2014-06-12
    • 2012-02-05
    相关资源
    最近更新 更多