【问题标题】:Semantic UI radio buttons fields does not work with Angular JS语义 UI 单选按钮字段不适用于 Angular JS
【发布时间】:2017-03-16 00:02:13
【问题描述】:

当我尝试将 Angular js 与语义 ui 集成时遇到问题(数据绑定不起作用),特别是当我使用如下代码之类的单选按钮字段时:

html

   <div ng-controller="MyCtrl">
        <div class="ui form">
            <div class="field">
                <div class="ui radio checkbox">
                   <input type="radio" ng-model="value" value="foo" ng-change="newValue(value)">
                </div>
            </div>
            <div class="field">
                <div class="ui radio checkbox">
                   <input type="radio"  ng-model="value" value="boo" ng-change="newValue(value)">
                </div>
            </div>    
         </div>
          {{value}}
    </div>

和控制器

var myApp = angular.module('myApp',[]);

function MyCtrl($scope) {
   $scope.value= 'foo'; 
   $scope.newValue = function(value) {
      console.log(value);
   }
}

【问题讨论】:

    标签: angularjs radio-button semantic-ui


    【解决方案1】:

    我认为您缺少控制器:

    myApp.controller('MyCtrl', function() {});

    那么你应该把你所有的逻辑都放在里面,否则我不确定如果不使用$apply来收集它,数据回收是否会起作用。

    【讨论】:

    • 对不起,我忘记写这行了,但无论如何它都不起作用。它仅在我不使用语义 ui 提供的包装 div 时才有效。语义单选按钮 javascript 似乎与 angular js 不兼容。
    【解决方案2】:

    您需要一个指令来与单选按钮进行数据绑定, 这很有用SemanticUI-Angular-checkbox

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-12
      • 2021-10-06
      • 1970-01-01
      • 2018-03-06
      • 2014-02-27
      • 1970-01-01
      • 2018-05-17
      • 2011-06-15
      相关资源
      最近更新 更多