Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS ui-router not working

I'm new to AngularJS and ui-router as well. I try to build an app following a pattern I have seen in a tutorial, but it doesn't seem to work. I inserted two alert statements but they don't run.

projectlist.html is not displayed either.

No errors on JS console.

What is the problem?

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

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>
like image 365
Adam Szabo Avatar asked Jan 04 '14 00:01

Adam Szabo


1 Answers

You need to use ui-view not ng-view

Also, otherwise() takes a URL not a route name. So in your case it should be:

$urlRouterProvider.otherwise('/api/Projects');
like image 196
Daniel Tabuenca Avatar answered Oct 16 '22 05:10

Daniel Tabuenca