我有我的app.js:
angular.module('myApp', ['ui.tree'])
.controller('myCtrl', function($scope) {
$scope.remove = function(scope) {
scope.remove();
};
$scope.toggle = function(scope) {
scope.toggle();
};
$scope.moveLastToTheBeginning = function() {
var a = $scope.data.pop();
$scope.data.splice(0, 0, a);
};
$scope.newSubItem = function(scope) {
var nodeData = scope.$modelValue;
nodeData.nodes.push({
id: nodeData.id * 10 + nodeData.nodes.length,
title: nodeData.title + '.' + (nodeData.nodes.length + 1),
nodes: []
});
};
$scope.collapseAll = function() {
$scope.$broadcast('angular-ui-tree:collapse-all');
};
$scope.expandAll = function() {
$scope.$broadcast('angular-ui-tree:expand-all');
};
index.html以:
开头<script type="text/javascript" src="angular.min.js"></script>
<script type="text/javascript" src="angular-ui-tree.min.js"></script>
<link rel="stylesheet" type="text/css" href="angular-ui-tree.min.css">
<link rel="stylesheet" type="text/css" href="bootstrap.min.css">
<div ng-app="myApp">
<div ng-controller="myCtrl">
<!-- Nested node template -->
我在app.js所在的文件夹中有angular-ui-tree.min.js和angular.min.js。仍然得到以下错误:
angular.min.js:6 Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.5.11/$injector/modulerr?p0=myApp&p1=Error%3A%20%5B%24injector%3Anomod%5D%20http%3A%2F%2Ferrors.angularjs.org%2F1.5.11%2F%24injector%2Fnomod%3Fp0%3DmyApp%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8000%2Fangular.min.js%3A6%3A426%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8000%2Fangular.min.js%3A25%3A235%0A%20%20%20%20at%20b%20(http%3A%2F%2Flocalhost%3A8000%2Fangular.min.js%3A24%3A282)%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8000%2Fangular.min.js%3A25%3A20%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8000%2Fangular.min.js%3A40%3A17%0A%20%20%20%20at%20q%20(http%3A%2F%2Flocalhost%3A8000%2Fangular.min.js%3A7%3A371)%0A%20%20%20%20at%20g%20(http%3A%2F%2Flocalhost%3A8000%2Fangular.min.js%3A39%3A382)%0A%20%20%20%20at%20fb%20(http%3A%2F%2Flocalhost%3A8000%2Fangular.min.js%3A43%3A381)%0A%20%20%20%20at%20c%20(http%3A%2F%2Flocalhost%3A8000%2Fangular.min.js%3A21%3A19)%0A%20%20%20%20at%20Gc%20(http%3A%2F%2Flocalhost%3A8000%2Fangular.min.js%3A21%3A332)
at angular.min.js:6
at angular.min.js:40
at q (angular.min.js:7)
at g (angular.min.js:39)
at fb (angular.min.js:43)
at c (angular.min.js:21)
at Gc (angular.min.js:21)
at se (angular.min.js:20)
at angular.min.js:323
at HTMLDocument.b (angular.min.js:192)
答案 0 :(得分:0)
如评论中所述,您的版本可能存在错误(Angular&amp; UI Tree)。
请参阅此Plunkr工作:https://plnkr.co/edit/U2U5vMi7m9G8BzC494ma?p=preview
<head>
<script data-require="angular.js@1.6.5" data-semver="1.6.5" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.5/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-tree/2.22.6/angular-ui-tree.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-tree/2.22.6/angular-ui-tree.min.css" />
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>