【问题标题】:rating directive from bootstrap-ui module if angular returns an error "Error: $compile:nonassign Non-Assignable Expression"如果 angular 返回错误“错误:$compile:nonassign Non-Assignable Expression”,则来自 bootstrap-ui 模块的评级指令
【发布时间】:2023-03-30 03:24:01
【问题描述】:

我正在尝试将引导模块的评级指令用于角度,但是当我点击星号进行评级时,角度会触发此错误

enter link description here

我了解产生此错误是因为我在模型中使用的值是 constnatn。 让我解释一下

我在 nrate.html 中有这个指令

<rating ng-model="rate" max="5" readonly="false" value="2"></rating>

还有这个控制器

appControllers.controller("singleRatingController", function ($scope, $http) {
    $scope.rate = 0;
});

所以我使用变量“rate”来加载速率值

在其他 html 页面中,我使用相同的指令和相同的控制器并且效果很好

谢谢

【问题讨论】:

    标签: angularjs angularjs-directive angular-ui-bootstrap


    【解决方案1】:

    使用 valueng-model,不能同时使用两者,具体取决于您使用的 UI Bootstrap 版本。

    两种情况的JS:

    appControllers.controller("singleRatingController", function ($scope, $http) {
      $scope.rate = 2;
    });
    

    HTML - 如果使用 0.11.0:

    <rating ng-model="rate" max="5" readonly="false"></rating>
    

    HTML - 如果使用 0.10.0 或以下:

    <rating value="rate" max="5" readonly="false"></rating>
    

    【讨论】:

    • 当然问题是因为我使用了 0.9.0 vesrion 并使用 ng-model 指令引起的。使用 value 而不是 ng-model 可以解决问题。谢谢
    猜你喜欢
    • 2016-05-30
    • 1970-01-01
    • 2014-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-01
    • 1970-01-01
    • 2019-02-19
    相关资源
    最近更新 更多