角形からサーバーコントローラーにデータを送信しようとしています 私のjsonファイルを変更するためにこれらのデータを使用しています.njResource バックエンドとFrontEndデータを通信するが、動作の仕組みを理解できなかった 以下は私の問題の説明に役立つと判断したコードの一部です。meanjsのサーバー(nodejs)コントローラーへのデータの送信方法
machine.client.view.html
<section data-ng-controller=’MachineController’>
<form class=’form-horizontal’ data-ng-submit=’create()’ novalidate>
<fieldset>
<div class="form-group">
<label class="control-label" for="projectName">Name of the project</label>
<div class="controls">
<input type="text" class="form-control" id="projectName" data-ng-model="projectName" placeholder="my_first_project">
</div>
<div class="form-group">
<input type="submit" class="btn btn-primary"></input>
</div>
</fieldset>
</form>
</section>
machine.client.routes.js
(function() {
'use strict';
//Setting up route
angular
.module('machine')
.config(routeConfig);
routeConfig.$inject = ['$stateProvider'];
function routeConfig($stateProvider) {
// Machine state routing
$stateProvider
.state('machine', {
url: '/machine',
templateUrl: 'modules/machine/client/views/machine.client.view.html',
controller: 'MachineController',
controllerAs: 'vm'
});
}
})();
machine.client.controller.js
(function() {
'use strict';
angular
.module('machine')
.controller('MachineController', MachineController);
MachineController.$inject = ['$scope'];
function MachineController($scope) {
var vm = this;
// Machine controller logic
$scope.create = function() {
console.log("Testing the functionalites");
console.log(this.projectName);
};
init();
function init() {}
}
})();
machine.server.controller.js
'use strict';
/**
* Module dependencies.
*/
require('require-xml');
var path = require('path'),
mongoose = require('mongoose'),
initialJsonFile = require('../resources/config.json'),
finalJsonFile = './modules/machine/server/config/config1.json',
updatedJson = require('../config/config1.json'),
js2xmlparser = require('js2xmlparser'),
jsonfile = require('jsonfile'),
errorHandler = require(path.resolve('./modules/core/server/controllers/errors.server.controller')),
_ = require('lodash');
/**
* Converting xml to json
*/
exports.updatingJsonConfig = function(req, res) {
//I do need here to get data from angular form the string 'testing description' it was only used to test the modifications
initialJsonFile.project.projectName = 'testing description';
};
machine.server.routes.js
'use strict';
var machine = require('../controllers/machine.server.controller');
module.exports = function(app) {
app.route('/testing').get(machine.updatingJsonConfig);
};
NB:私は問題を説明するだけにフォームで1つの入力を使用し、それが複数のフィールド
の一形態であります
は私の問題は私のシナリオではこのようなユーザ入力である(角コントローラからupdatingJsonConfig関数にデータを送信する方法であるプロジェクト名私がProjectController(angle側)にprojectName値を取得したときに、その値(projectName)をServerController(updatingJsonConfigのもの)に送信することです。 req.body.projectNameをチェックするために何の価値もなかったので、私の質問です。注:私のサーバーは設定されており、ブラウザー要求でJsonConfigを更新してサーバー側のコントローラーをテストすることに成功しました。 – user3557777
申し訳ありません私は、あなたがリクエストと共に送信されるデータを持っていることを見落としました。あなたはPOSTを使うべきです。更新された答え。 – marton