gpt4 book ai didi

javascript - Angular ui-select $injector :unpr error

转载 作者:行者123 更新时间:2023-11-29 23:48:21 30 4
gpt4 key购买 nike

我试图在我的系统中使用 ui-select 模块,我注入(inject)了 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

最佳答案

尝试更新 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>

关于javascript - Angular ui-select $injector :unpr error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43397222/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com