急性选择:必须在Angular Js中设置ac-options和ac-model属性

时间:2017-06-06 05:59:13

标签: javascript angularjs

我需要acute select。我已经提到了enter link description here

添加所有这些依赖项后,在控制台中出现错误

MainPage.html

<ac-select ac-model='hospitalData.hospitalName' 
 ac-options='hospital.hospitalName as hospital.hospitalName for hospital in hospNameList' 
 ac-change='selectionChanged(value)' 
 ac-settings='{ loadOnOpen: true }'></ac-select>
  

错误

ac-options and ac-model attributes must be set <ac-select ac-model="hospitalData.hospitalName" ac-options="hospital.hospitalName as hospital.hospitalName for hospital in hospNameList" ac-change="selectionChanged(value)" ac-settings="{ loadOnOpen: true }" class="ng-isolate-scope">

Controller.js

scope.hospitalData=null;
scope.hospitalData.hospitalName=null;
scope.hospNameList=null;
//added above after refferring issue on github,But still not working    

gethospNameList();
function gethospNameList() {
    Repository.gethospNameList().then(
    function(result) {
      scope.hospNameList = result;
      console.log("hospNameList :"+ scope.hospNameList);
    });
};

1 个答案:

答案 0 :(得分:1)

以下是使用angular-ui-select

的解决方案

以下只是一个片段

检查柱塞是否有工作代码:

var app = angular.module('myApp', ['ui.select']);
app.controller('myCtrl', function($scope) {
    $scope.superhero = {
      selected: 'Sravan'
    };
       
    $scope.getSuperheroes = function(search) {
     var newSupes = $scope.superheroes.slice();
      if (search && newSupes.indexOf(search) === -1) {
        newSupes.unshift(search);
      }
      return newSupes;
    }
    
    $scope.superheroes = [
      'Sravan',
      'Hema',
      'AnotherUser',
        
    ];
});

    
<html>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
  <link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/3.4.5/select2.css">    
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.8.5/css/selectize.default.css">
  <script type="text/javascript" src="script.js"></script>
  <script type="text/javascript" src="select.js"></script>
    <link rel="stylesheet" href="style.css">

  <body>
    <div ng-app="myApp">
      <div ng-controller="myCtrl">
        <div class="row">
          <div class="form-group">
            <div class="col-sm-6">
              <ui-select ng-model="superhero.selected">
                <ui-select-match placeholder="Select or search a superhero ...">{{$select.selected}}</ui-select-match>
                <ui-select-choices repeat="hero in getSuperheroes($select.search) | filter: $select.search">
                  <div ng-bind="hero"></div>
                </ui-select-choices>
              </ui-select>
            </div>
            <label class="col-sm-3 control-label">You have chosen {{ superhero.selected }}!</label>
          </div>
        </div>
      </div>
    </div>
  </body>

</html>

Here is a working Plunker