Angular ui-select $ injector:unpr错误

时间:2017-04-13 16:18:16

标签: javascript angularjs ui-select

我尝试在我的系统中使用ui-select模块,我注入了ui-modulengSanitize

angular.module('app', ['ngSanitize', 'ui.select']);

并将JS文件包含在HTML

<link rel="stylesheet" href="/local/mentoring/assets/ui-select/dist/select.min.css">
<script src="/local/mentoring/assets/ui-select/dist/select.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.18/angular-sanitize.js"></script>

            <div ng-controller="ctrl">
                <ui-select ng-model="selected.value">
                    <ui-select-match>
                        <span ng-bind="$select.selected.name"></span>
                    </ui-select-match>
                    <ui-select-choices repeat="item in (itemArray | filter: $select.search) track by item.id">
                        <span ng-bind="item.name"></span>
                    </ui-select-choices>
                </ui-select>
            </div>

我的JS:

angular.module('app')
        .controller('ctrl', ['$scope', function ($scope){
            $scope.itemArray = [
                {id: 1, name: 'first'},
                {id: 2, name: 'second'},
                {id: 3, name: 'third'},
                {id: 4, name: 'fourth'},
                {id: 5, name: 'fifth'},
            ];

            $scope.selectedItem = $scope.itemArray[0];
        }]);

但是当我使用该指令时,向我报告以下错误:

ui-select error

我的代码错了什么?

更新1:

我将angular.min.js更改为angular.js,然后我的控制台报告了以下错误:

enter image description here

1 个答案:

答案 0 :(得分:1)

尝试更新ui.select版本。这是一个有效的解决方案。

<强>样本

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

myApp.controller('Controller', ['$scope',
  function($scope) {
    $scope.itemArray = [{
      id: 1,
      name: 'first'
    }, {
      id: 2,
      name: 'second'
    }, {
      id: 3,
      name: 'third'
    }, {
      id: 4,
      name: 'fourth'
    }, {
      id: 5,
      name: 'fifth'
    }, ];

    $scope.selectedItem = $scope.itemArray[0];
  }
]);
<!DOCTYPE html>
<html>
<head>
  <script src="https://code.angularjs.org/1.4.0-beta.6/angular.js"></script>
  <script src="https://code.angularjs.org/1.4.0-beta.6/angular-sanitize.js"></script>
  <link href="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-select/0.20.0/select.css" />
  <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-select/0.20.0/select.min.js"></script>
  <script src="script.js"></script>
</head>
<body ng-app="myApp">
  <div ng-controller="Controller">
    <ui-select ng-model="selected.value">
      <ui-select-match>
        <span ng-bind="$select.selected.name"></span>
      </ui-select-match>
      <ui-select-choices repeat="item in (itemArray | filter: $select.search) track by item.id">
        <span ng-bind="item.name"></span>
      </ui-select-choices>
    </ui-select>
  </div>
</body>
</html>