Ada*_*abo 27 angularjs angular-ui-router
我也是AngularJS和ui-router的新手.我尝试按照我在教程中看到的模式构建应用程序,但它似乎不起作用.我插入了两个alert语句,但它们没有运行.
projectlist.html 也没有显示.
JS控制台没有错误.
问题是什么?
JS:
var EntityEditorApp = angular.module('EntityEditorApp', ['ngResource', 'ui.router'])
.config(function ($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/');
$stateProvider
.state('/', {
url: '/api/Projects',
templateUrl: 'projectlist.html',
controller: 'ListCtrl'
});
});
EntityEditorApp.factory('Project', function ($resource) {
alert(1); // This does not run
return $resource('/api/Project/:id', { id: '@id' }, { update: { method: 'PUT' } });
});
var ListCtrl = function ($scope) {
alert(1); // This does not run
$scope.projects = [];
$scope.search = function () {
Project.query(function (data) {
$scope.projects = $scope.projects.concat(data);
});
};
$scope.search();
};
Run Code Online (Sandbox Code Playgroud)
HTML:
<!DOCTYPE html>
<html ng-app="EntityEditorApp" xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="Scripts/jquery-1.10.2.js"></script>
<script src="Scripts/bootstrap.js"></script>
<script src="Scripts/angular.js"></script>
<script src="Scripts/angular-route.js"></script>
<script src="Scripts/angular-resource.js"></script>
<script src="Scripts/AngularUI/ui-router.js"></script>
<script src="Scripts/app/entityeditor.js"></script>
<link href="Content/bootstrap.css" rel="stylesheet" />
<title>AngularJS Tutorial Todo App</title>
</head>
<body>
<div class="container">
<div ng-view></div>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
dta*_*enc 82
您需要使用ui-view不 ng-view
另外,否则()采用URL而不是路由名称.所以在你的情况下它应该是:
$urlRouterProvider.otherwise('/api/Projects');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
29279 次 |
| 最近记录: |