I am new to angular and express, MeanJs so need help. What I am doing wrong, how to post data and get answer?
I want to execute Complile function and pass the code from text box to server and do something with it and get answer.
But how to write code in lab.client.service.js or others files?
Becouse I do not get any information that starting from file [3] the code were executed.
I wrote this code using https://www.youtube.com/watch?v=DOqLbJTvCv8&feature=youtu.be tutorial.
Files
lab.client.view.html I have text box with binds to data.code angular object
<textarea ng-model="data.code"></textarea>
and have two buttons with trigers functions in :
<div style="margin:12px;">
<button type="button" class="btn btn-primary" ng-click="LabController.compile()">Compile</button>
<button type="button" class="btn btn-primary" ng-click="LabController.compileAndUpload()">Cimpile & Upload</button>
</div>
lab.client.controller.js
'use strict'; angular.module('core').controller('LabController', ['$scope', 'Lab', function($scope, Lab) { $scope.data = { code: '' }; this.compile = function() { console.log('User clicked compile', $scope.data.code); //This message is printed in browser console. $scope.message = Lab.compile //But this action does not executes??? }; this.compileAndUpload = function() { console.log('User clicked compileAndUpload', $scope.data.code); //This message is printed in browser console. $scope.message = Lab.compileAndUpload; //But this action does not executes??? }; } ]);
lab.client.service.js
'use strict'; angular.module('core').factory('Lab', ['$resource', function($resource) { console.info("client.service: Veikia!"); return $resource('lab', { compile: { //I do not see that there URL were triggered method: 'POST', url: '/lab/compile' }, compileAndUpload: { //I do not see that there URL were triggered method: 'POST', url: '/lab/compileAndUpload', } }); } ]);
lab.server.routes.js
'use strict'; module.exports = function(app) { var lab = require('../../app/controllers/lab.server.controller'); // Lab Routes app.route('/lab/compile') .post(lab.compile); app.route('/lab/compileAndUpload') .post(lab.compileAndUpload); };
lab.server.controller.js
'use strict'; var mongoose = require('mongoose'), _ = require('lodash'); var response = { 'message' : 'It works' }; exports.compile = function(req, res) { var code = req.body.data.code; res.jsonp(response); }; exports.compileAndUpload = function(req, res) { var code = req.body.data.code; res.jsonp(response); };