Angular $ injector:modulerr模块错误

时间:2016-02-29 08:17:58

标签: javascript angularjs html5 angularjs-ng-route

我不知道导致此错误的原因:Click to see the error

我正在尝试创建动态Web应用程序。我是否需要本地服务器才能运行此应用程序。目前我没有使用任何本地服务器。

HTML:

<div class = "body" ng-controller = "app">
  <div class = "column2">
    <div class = "sectionName">
       <span class = "sectionName-Span">{{ page.title() }}</span>
       <div class = "container">
          <ng-view>Something went wrong</ng-view>
       </div>
    </div>
  </div>
  <script type=text/ng-template id=profile.html>
     I'm Lalinda Sampath Dias
  </script>

Controller.js:

var application = angular.module('mainApp', ['appServices'])
    .config(['$routeProvider', function($routeProvider) {
        $routeProvider.
                when('/tab1', {templateUrl: 'profile.html',   controller: HomeCtrl}).
                when('/tab2', {templateUrl: 'list.html',   controller: ListCtrl}).
                otherwise({redirectTo: '/tab1'});
}]);


/* Controllers */

function MainCtrl($scope, Page) {
    console.log(Page);
    $scope.page= Page; 
}

function HomeCtrl($scope, Page) {
    Page.setTitle("Welcome");
}


function ListCtrl($scope, Page, Model) {
    Page.setTitle("Items");
    $scope.items = Model.notes();

}

function DetailCtrl($scope, Page, Model, $routeParams, $location) {
    Page.setTitle("Detail");
    var id = $scope.itemId = $routeParams.itemId;
    $scope.item = Model.get(id);
}

function SettingsCtrl($scope, Page) {
    Page.setTitle("Settings");
}

/* Services */

angular.module('appServices', [])

        .factory('Page', function($rootScope){
            var pageTitle = "Untitled";
            return {
                title:function(){
                    return pageTitle;
                },
                setTitle:function(newTitle){
                    pageTitle = newTitle;
                }
            }
        })

        .factory ('Model', function () {
            var data = [
                {id:0, title:'Doh', detail:"A dear. A female dear."},
                {id:1, title:'Re', detail:"A drop of golden sun."},
                {id:2, title:'Me', detail:"A name I call myself."},
                {id:3, title:'Fa', detail:"A long, long way to run."},
                {id:4, title:'So', detail:"A needle pulling thread."},
                {id:5, title:'La', detail:"A note to follow So."},
                {id:6, title:'Tee', detail:"A drink with jam and bread."}
            ];
            return {
                notes:function () {
                    return data;
                },
                get:function(id){
                  return data[id];
                },
                add:function (note) {
                    var currentIndex = data.length;
                    data.push({
                        id:currentIndex, title:note.title, detail:note.detail
                    });
                },
                delete:function (id) {
                    var oldNotes = data;
                    data = [];
                    angular.forEach(oldNotes, function (note) {
                        if (note.id !== id) data.push(note);
                    });
                }
            }
});

编辑:

<body ng-app = "mainApp">
        <div id = "background-div">
            <div class = "header">
                <div class = "ham-icon">
                    <img src = "images/ham-icon.png">
                </div>
                <div class = "logo">
                    <span class = "google-logo">Lalinda</span><span class = "hangouts-logo"> Sampath</span>
                </div>
                <div class = "profile-data">
                </div>
            </div>
            <div class = "body" ng-controller = "app">
                <div class = "column1">
                    <div class = "tab1">
                        <a href = "#/tab1"><img src = "images/people-icon.png"></a>
                    </div>
                    <div class = "tab2">
                        <a href = "#/tab2"><img src = "images/chat-icon.png"></a>
                    </div>
                    <div class = "tab3">
                        <a href = "#/tab3"><img src = "images/phone-icon.png"></a>
                    </div>
                    <div class = "tab4">
                        <a href= "#/tab4"><img src = "images/other-icon.png"></a>
                    </div>
                </div>
                <div class = "column2">
                    <div class = "sectionName">
                        <span class = "sectionName-Span">{{ page.title() }}</span>
                        <div class = "container">
                            <ng-view>Something went wrong</ng-view>
                            <!--input type = "text" ng-model = "name"-->
                        </div>
                    </div>
                </div>
                <script type=text/ng-template id=profile.html>
                    I'm Lalinda Sampath Dias
                </script>
                <div class = "column3">
                    <div classs = "user-greet">
                        <span class = "user-greet-span">Hi, Guest</span>
                    </div>
                    <div class = "det">
                        <span class = "det-span">Get started by calling or messaging a friend below</span>
                    </div>
                    <div class = "functional-area">
                        <div class = "video-call">
                        </div>
                        <div class = "phone-call">
                        </div>
                        <div class = "message">
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </body>

2 个答案:

答案 0 :(得分:1)

您需要添加ngRoute作为此类

的依赖项
var application = angular.module('mainApp', ['ngRoute','appServices'])

答案 1 :(得分:0)

通过我自己找出答案。添加ngRoute作为依赖项时,我们必须加载ngRoute.js文件。您可以从互联网上下载。

以下是Google CDN:   https://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular-route.js