Угловое приложение не загружается?

0

Я пытаюсь понять, почему мое угловое приложение не работает.

поэтому у меня есть следующий код:

app.modules.js

angular.module("quickscan", [
        "ui.router",

        "quickscan.controllers"
]);

angular.module("quickscan.controllers", []);

app.routes.js

var app = angular.module("quickscan");

app.config(function ($stateProvider, $urlRouterProvider, $controllerProvider, $compileProvider, $filterProvider, $provide, $httpProvider) {
    $urlRouterProvider.otherwise("/test");

    $stateProvider
        .state("app", {
            abstract: true,
            templateUrl: "shared/Layout/Main.html"
        })
        .state("app.root", {
            url: "/test",
            templateUrl: "shared/Main/Main.html"
        })
        .state("buildings", {
            url: "/buildings",
            controller: "BuildingDetailController",
            templateUrl: "components/BuildingDetail/BuildingDetailView.html"
        });
});

index.html

<!DOCTYPE html>
<html>
<head>
    <title>Quickscan App v2</title>
    <meta http-equiv="X-UA-Compatible" content="IE=9" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=no">
    <link rel="stylesheet" href="content/css/app.css">
</head>
<body>

    <div ng-view id="view"></div>

    <!-- order dependend scripts -->
    <script src="scripts/jquery/jquery.js"></script>
    <script src="scripts/angular/angular.js"></script>
    <script src="app/app.module.js"></script>

    <!--remaining scripts-->
    <script src="content/js/scripts.js"></script>

    <!--angular scripts-->
    <script src="content/js/all.js"></script>

    <script>
        setTimeout(function() {
            angular.bootstrap(document, ['quickscan']);
            console.log("Hello");
        }, 3000);

    </script>

</body>
</html>

all.js

(function () {

    var app = angular.module("quickscan");

    app.config(function ($stateProvider, $urlRouterProvider, $controllerProvider, $compileProvider, $filterProvider, $provide, $httpProvider) {
        $urlRouterProvider.otherwise("/test");

        $stateProvider
            .state("app", {
                abstract: true,
                templateUrl: "shared/Layout/Main.html"
            })
            .state("app.root", {
                url: "/test",
                templateUrl: "shared/Main/Main.html"
            })
            .state("buildings", {
                url: "/buildings",
                controller: "BuildingDetailController",
                templateUrl: "components/BuildingDetail/BuildingDetailView.html"
            });
    });

})(); 
var Building = function (data) {
 // some other class
    return building;
};

var Category = function (data, parent, building) {
        // some class 
    return category;
};

(function () {
    "use strict";

    angular
        .module("quickscan.controllers")
        .controller("BuildingDetailController",
        function ($scope, $rootScope) {
            var vm = this;
            vm.title = "Building Detail";

            function activate() {
                console.log("test");
            }

            activate();

        });
})();
(function () {
    "use strict";

    angular
        .module("quickscan.controllers")
        .controller("CategoryDetailController",
        function ($scope, $rootScope) {
            var vm = this;
            vm.title = "Building Detail";

            function activate() {
                console.log("test");
            }

            activate();

        });
})();

но приложение не загружает ни одно из моих просмотров, мои контроллеры не сообщают об test и не перенаправляются на /# не появляются какие-либо ошибки, у кого есть ключ?

  • 0
    Пробовал инициализировать приложение в html с помощью ng-app ?
  • 0
    Да, тот же результат, что и при ручной загрузке
Показать ещё 2 комментария

1 ответ

2
Лучший ответ

Похоже, вы не используете директиву ui-view, см. Https://github.com/angular-ui/ui-router/wiki/The-Components

Ваш

<div ng-view id="view"></div>

Должно быть

<div ui-view></div>
  • 0
    Ух ты, как я скучал по тому, чего я не знаю, но это действительно было проблемой, спасибо!
  • 0
    Добро пожаловать !, эта ссылка полна полезного чтения, так что взгляните на другие функции UI-роутера, он очень мощный :)

Ещё вопросы

Сообщество Overcoder
Наверх
Меню