Angular: how to pass $scope variables into the Node.js server.
Date : March 29 2020, 07:55 AM
it helps some times When you use ng-model it is to bind your form components to the scope using certain name. this means that <input ng-model="stickie_text" type="text" id="sticky_content" />
<form ng-submit="submit()" ng-controller="formCtrl">
<input ng-model="stickie_text" type="text" id="sticky_content" />
<button type="submit" id="add_sticky" value="add a new stickie!">new sticky</button>
</form>
$scope.submit = function() {
$http
.post('/api/stickies', {what: to, put: here})
.success(function(data){
//what to do here
})
.error(function(data){
console.log('Error: ' + data);
});
};
app.post('/api/stickies',function(req,res){
var test = req.body.stickie;
db.run("INSERT INTO stickies (data) VALUES (?)", [ test ]);
});
$scope.submit = function() {
$http
.post('/api/stickies', {stickie: $scope.stickie_text})
.success(function(data){
//what to do here? it's up to you and the data you write from server.
})
.error(function(data){
console.log('Error: ' + data);
});
};
ng-model="formData.stickie"
$scope.submit = function() {
$http
.post('/api/stickies', $scope.formData)
.success(function(data){
//what to do here? it's up to you and the data you write from server.
})
.error(function(data){
console.log('Error: ' + data);
});
};
|
How do I pass node.js server variables into my angular/html view?
Date : March 29 2020, 07:55 AM
seems to work fine This is a two step process. First, you need to use a library(server library) like express in node to set the proper routings (REST Services) to respond to your Requests: //app = express();
app.get('/api/:paramID1/:paramID2',function(req, res){
return res.json({ A: 5 });
});
$http.get( "/api/1/abc").success(function( data ) {
$scope.A= data; //from your sample;
alert( "Load was performed. " + data );
});
|
Pass in Angular variables when starting app with node
Date : March 29 2020, 07:55 AM
I hope this helps you . You can use the grunt-template module. Add your app.js file as app.js.tpl. var options = {};
options.api = {};
options.api.base_url = "<%= base_url %>";
module.exports = function(grunt) {
grunt.initConfig({
'template': {
'process-js-template': {
'options': {
'data': {
'base_url': 'http://myDomainName.tld:8080'
//Can also use 'base_url': grunt.option('base_url')
//If you wanted to take it from the CLI.
//EG: grunt default --base_url=http://myDomainName.tld:8080
}
},
'files': {
//The key being where you want to save the file.
'path/to/app.js': ['path/to/app.js.tpl']
}
}
}
});
grunt.loadNpmTasks('grunt-template');
grunt.registerTask('default', [
'template'
]);
};
|
Need to pass $scope with variables to another page in angular?
Date : March 29 2020, 07:55 AM
I wish this help you New route renders new template and also bind new scope to template. So you can't really just use the same scope for both routes. However, there are at least two workarounds. 1). $rootScope. $rootScope is available in all views so you can store some data in it and be able to access it in any template.
|
Best way to pass variables from Symfony2 to Angular scope
Date : March 29 2020, 07:55 AM
|