Angular modal pass data to controller and view

ANGULAR SCRIPT

var $ctrlb = this;

$ctrl.edit = function (item, size, parentSelector) {

$scope.app_data={};
$scope.app_data.ad_name = item.ad_name;
$scope.app_data.ad_package = item.ad_package;
$scope.app_data.ad_description = item.ad_description;
$scope.app_data.ad_icon = item.ad_icon;

var parentElem = parentSelector ?
angular.element($document[0].querySelector('.modal-demo ' + parentSelector)) : undefined;
var modalInstance = $uibModal.open({
scope: $scope,
animation: $ctrl.animationsEnabled,
ariaLabelledBy: 'modal-title',
ariaDescribedBy: 'modal-body',
templateUrl: 'editadmodal.html',
controller: 'editad',
controllerAs: '$ctrlb',
size: size,
appendTo: parentElem,
resolve: {

app_data: function () {
return $scope.app_data;
}
}
});

modalInstance.result.then(function (selectedItem) {
$ctrl.selected = selectedItem;
}, function () {
// $log.info('Modal dismissed at: ' + new Date());
});
}

HTML

CONTROLLER

 app.controller('editad', function ($scope, $uibModalInstance, $http, $cookies, Upload, $window) {

$scope.ok = function () {

alert($scope.editad.appname);

$uibModalInstance.dismiss('cancel');

}
$scope.cancel = function () {
$uibModalInstance.dismiss('cancel');
};
});

Nodejs upload picture / file with angular

NODE CODE

npm install connect-multiparty

var multiparty = require('connect-multiparty'), multipartyMiddleware = multiparty({ uploadDir: '/var/www/html/beetalk/myads/imagesb' });

var bodyParser = require('body-parser')
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));

app.post('/addnewad', multipartyMiddleware, function(req, res) {

//console.log(req.body, req.files);

res.send(req.files);

console.log(req.body, req.files);

});

ANGULAR / HTML

var app = angular.module("myApp", ["ngRoute", 'ngCookies','ngAnimate', 'ngSanitize', 'ui.bootstrap','ngFileUpload']);

app.controller('addnewad', function ($scope, $uibModalInstance, $http, $cookies, Upload) {

$scope.upload = function (file) {

Upload.upload({
url: 'https://www.beetalkweb.com:8443/addnewad',
data: {file: file, 'appname': "abc"}
}).then(function (resp) {
alert('Success ' + resp.config.data.file.name + 'uploaded. Response: ' + JSON.stringify(resp.data));
console.log('Success ' + resp.config.data.file.name + 'uploaded. Response: ' + resp.data);
}, function (resp) {
alert( console.log('Error status: ' + resp.status));
console.log('Error status: ' + resp.status);
}, function (evt) {
var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
console.log('progress: ' + progressPercentage + '% ' + evt.config.data.file.name);
});
};

$scope.ok = function () {

// alert($cookies.get('username'));
$scope.upload($scope.file);
// alert($scope.addnewad.appname+" "+$scope.addnewad.apppackage+" "+$scope.addnewad.appdescription)

$uibModalInstance.dismiss('cancel');

}
$scope.cancel = function () {
$uibModalInstance.dismiss('cancel');
};
});

How to get and set cookies using angular and jquery

SET COOKIES JQUERY

< script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
< script src="//cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js">
$.cookie('username', $scope.username, { expires: 99, path: '/' });

GET COOKIES ANGULAR

 < script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js">
< script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular-cookies.js">

var app = angular.module("myApp", ["ngRoute",'ngCookies']);
app.controller('myCtrl', function($window,$scope,$cookies) {

$scope.usercookies = $cookies.get('username');

});

Connect Angular with Nodejs using post and passing parameters using https

ANGULAR FILE

var app = angular.module('myApp', []);
app.controller('myCtrl', function($window,$scope, $http) {

// $http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";

$scope.username="ferran";
$scope.password="1234";

$scope.loginb = function() {

// alert($scope.username+" "+$scope.password);
// $http.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
$http({
url: 'https://www.beetalkweb.com:8443/login',
method: "POST",
data: {username:$scope.username,password:$scope.password}
// headers: {'Content-Type': 'application/x-www-form-urlencoded'}

})
.then(function(response) {

if(response.data=="true"){

$window.location.href = 'https://www.beetalkweb.com/myads/dashboard.html'; //You should have http here.

}else{

$scope.content="Username and Password not match";

}

},
function(response) {

alert(response.data+" error");

$scope.content = response.data;

});

};

NODEJS FILE

app.post('/login', function (req, res) {

MongoClient.connect(url, function(err, db) {
if (err) throw err;
var dbo = db.db("myads");

var query = {username: req.body.username, password: req.body.password };

dbo.collection('users').findOne(query, function (err, result) {
if (err){
res.send('error');
}
else if(!result){

// res.send(req.body.username+" "+req.body.password);
res.send('notmatch');

}else{
res.send('true');
//res.send(result);
}

db.close();

});
});
})

Connect Nodejs Mongodb and Angular with https

nodejs file

var fs = require('fs');
var https = require('https');
var privateKey = fs.readFileSync('certs/www.beetalkweb.com.key', 'utf8');
var certificate = fs.readFileSync('certs/bba86444d2e3bca1.crt', 'utf8');

var credentials = {key: privateKey, cert: certificate};
var express = require('express');
var app = express();

var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://Fespunaa:1982Fesp1982@127.0.0.1:27017/";

var bodyParser = require('body-parser')

app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});

app.get('/', function(req, res, next) {
// Handle the get for this route
res.render('index', {});

});

app.post('/', function(req, res, next) {
// Handle the post for this route
});

app.get('/conne', function (req, res) {

MongoClient.connect(url, function(err, db) {
if (err) throw err;
var dbo = db.db("myads");

dbo.collection("ads").find({"ad_name":"adname"}).toArray(function(err, result) {

if (err) throw err;

res.send(result);

db.close();
});
});

})

app.post('/conne', function (req, res) {

MongoClient.connect(url, function(err, db) {
if (err) throw err;
var dbo = db.db("myads");

dbo.collection("ads").find({"ad_name":"adname"}).toArray(function(err, result) {

if (err) throw err;

res.send(result);

db.close();
});
});

})

var httpsServer = https.createServer(credentials, app);
httpsServer.listen(8443);

Angular / html file


WeTalk



{{content}}


ver en editar texto innterior