本文介绍了急性选择:必须在Angular Js中设置ac-options和ac-model属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要急性选择。我已经提到了这个

I need acute select. I have referred this enter link description here

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

Am getting error in console after adding all these dependencies

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);
    });
};


推荐答案

以下是使用的解决方案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>

这篇关于急性选择:必须在Angular Js中设置ac-options和ac-model属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 02:56