AngularJS模块创建

时间:2016-01-06 07:53:39

标签: angularjs

我正在创建简单的angularJS应用程序,但我陷入了第一步。我不知道为什么,但由于某种原因我的模块没有被创建,我收到以下错误

Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.3.14/$injector/modulerr?p0=dataFinderApp&p1=E…gleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.14%2Fangular.min.js%3A38%3A135)

有人能告诉我这里有什么不对吗?

这是我的代码:

<%@ page session="false" %>
<html>
<head>
<title>Upload File Request Page</title>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.5/angular-route.min.js"></script>
<script type="text/javascript"">
var sampleApp = angular.module('dataFinderApp',[]);

sampleApp.config(function($routeProvider){

    $routeProvider.when('/',{
        templateUrl : '/upload.jsp', 
        controller : 'mainController'
    })
    .when('/progress',{         
        templateUrl : '/progress.jsp', 
        controller : 'mainController'
    })
    .when('/joblist',{          
        templateUrl : '/joblist.jsp', 
        controller : 'mainController'
    })
    .otherwise({redirectTo : '/'});
});

sampleApp.directive('fileModel', ['$parse', function ($parse) {
    return {
        restrict: 'A',
        link: function(scope, element, attrs) {
            var model = $parse(attrs.fileModel);
            var modelSetter = model.assign;

            element.bind('change', function(){
                scope.$apply(function(){
                    modelSetter(scope, element[0].files[0]);
                });
            });
        }
    };
}]);

sampleApp.service('fileUpload', ['$http', function ($http) {
    this.uploadFileToUrl = function(file, uploadUrl){
        var fd = new FormData();
        fd.append('file', file);
        $http.post(uploadUrl, fd, {
            transformRequest: angular.identity,
            headers: {'Content-Type': undefined}
        })
        .success(function(){
        })
        .error(function(){
        });
    }
}]);

sampleApp.controller('mainController', ['$scope', 'fileUpload', function($scope, fileUpload){

    $scope.uploadFile = function(){
        alert("Vall");
        var file = $scope.myFile;
        console.log('file is ' );
        console.dir(file);
        var uploadUrl = "/uploadFile";
        alert('val');
        fileUpload.uploadFileToUrl(file, uploadUrl);
    };

}]);

</script>
</head>
<body ng-app="dataFinderApp">

<!-- <div ng-controller="mainController">
    <input type="file" file-model="myFile"/>
    <button ng-click="uploadFile()">Upload</button>
</div>

<div ng-view></div>  -->

</body>
</html>

3 个答案:

答案 0 :(得分:3)

在AngularJS 1.2.0及更高版本中,user_id已移至其自己的模块。如果在升级到1.2.x或更高版本后出现此错误,请确保已安装ngRoute

答案 1 :(得分:1)

您可以尝试使用代码段:

#include<iostream>
using namespace std;


#ifndef HEADERFILE_H_
#define HEADERFILE_H_

void function1();

#endif /* HEADERFILE_H_ */


int main(){

function1();

    cout<<"this is main function from mainFile"<<endl;
    return 0;
}

答案 2 :(得分:0)

你必须使用:

var sampleApp = angular.module('dataFinderApp',['ngRoute']);

发生此错误是因为您没有包含ngRoute模块。