角度アプリ(バージョン1.5.7)を作成してherokuに展開したいと考えています。角度コントローラがノードエクスプレスで動作しない
ノードを実装し、expressを使用してherokuがメインのindex.htmlファイルを提供して、それを作成する必要がありました。しかし、私がこれをしたとき、私のコントローラの両方が壊れました。私のコンタクトフォームコントローラは、自分のメッセージを表示せず、フッタコントローラもレンダリングしませんでした。
とコンソールに私は読み込みエラーを取得:
を「[NG AREQ]引数 『contactCtrl』の関数ではありませんが、未定義だ」あなたはここに住んでビルドをチェックアウトすることができます - https://fathomless-scrubland-50887.herokuapp.comとのための私のgithubのをここでは、このプロジェクト - https://github.com/StephenGrable1/AngularJS-Single-Page
ここでは私の急行server.jsファイル
var express = require('express');
var app = express();
var port = process.env.PORT || 8080;
app.use(express.static(__dirname));
app.get('/', function(req, res) {
res.sendfile('index.html', {root: __dirname })
});
app.listen(port, function() {
console.log('Our app is running on port ' + port);
});
私はノードとexpreを実装する前に、これらが正常に動作2つのコントローラでありますss。
footer.js
angular
.module('Single-Page-App')
.directive('appFooter', function() {
return {
restrict: 'E',
template: '© Name {{ getYearCtrl.date | date:"yyyy" }}',
controller: function(){
this.date = Date.now();
},
controllerAs:'getYearCtrl'
};
});
contactCtrl.js
angular
.module('Single-Page-App')
.controller('contactCtrl', ['$scope', '$http', function($scope, $http){
$scope.contact = {name : '', email : '', subject : '', message : ''};
$scope.submitForm = function() {
var config = {
method: 'POST',
url : '../php/process-form.php',
data : {
'name' : $scope.contact.name,
'email': $scope.contact.email,
'subject': $scope.contact.subject,
'message' : $scope.contact.message
}
};
var request = $http(config);
request.then(function (response){
if(typeof(response.data) == 'string') {
// make all error messages blank when
// php return a string (which is the success message)
// which means there are no error messages being sent from php
$scope.nameError = "";
$scope.messageError = "";
$scope.subjectError = "";
$scope.emailError = "";
// put the success string from php into
// the successMsg so it can be accessed in the view
$scope.successMsg = response.data;
// clear all form values
// and set the inputs to prisitine and untouched
// so that angular will not display any error messages
// once a user submits the form successfully
$scope.contact = {};
$scope.contactForm.$setPristine();
$scope.contactForm.$setUntouched();
console.log($scope.successMsg);
console.log("not an object");
} else {
if(typeof(response.data) == 'object') {
// if php sends an object
// (which contains all the error messages present)
// populate variables with error messages
$scope.nameError = response.data['name-error'];
$scope.messageError = response.data['message-error'];
$scope.subjectError = response.data['subject-error'];
$scope.emailError = response.data['email-error'];
//clear the success message if errors come back from php
$scope.successMsg = "";
console.log("it is an object");
}
}
}, function (error){
$scope.msg = error.data;
console.log($scope.msg);
});
}
}]);
私は私のコントローラの機能を破壊されたかわからないんだけど...
編集:これは私のmain.jsファイルで、ルートは
ですvar app = angular.module('Single-Page-App', ['ui.router', 'ngMessages']);
app.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/home');
$stateProvider
.state("home", {
url:"/home",
views: {
"[email protected]": {
templateUrl: "partials/home.html"
}
}
})
.state("listen", {
url:"/listen",
views: {
"[email protected]": {
templateUrl: "partials/listen.html"
}
}
})
.state("watchHere", {
url:"/watch",
views: {
"[email protected]": {
templateUrl: "partials/watch.html"
}
}
})
.state("contact", {
url:"/contact",
views: {
"[email protected]": {
templateUrl: "partials/contact.html"
}
}
})
}])
angular.bootstrap(document, ['Single-Page-App']);
あなたがHTML内のライブラリのすべてのパスをチェックして使用して
contactCtrl
定義し、プラスあなたは私が急行し、ノードに実装する前にライブラリへのパスが働いていたこの –のコンソールでいくつかのエラーログを提供することができます。私はそれがここの問題だとは思わない。私が質問に言ったように、私が得ているエラーは "[ng:areq]引数 'contactCtrl'は関数ではなく、未定義です" –
あなたのhtmlは 'ng-app'と' ng-controller ' ' – gianlucatursi