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');
};
});

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

Http request POST with params – Angular –

This is post is about how to connect angular with server with a simple post request with params.


app.controller("loginController", function($scope, $http) {

    $scope.login = function (){

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

            $http({
                url: 'http://topzapp.com/index.php/landingcontroller/ctrl_login',
                method: "POST",
                data: { 'email' :  $scope.email,'password' :  $scope.password }
            })
                .then(function(response) {

                        $scope.content = response.data;

                        if(response.data == '1'){
                                window.open('http://topzapp.com/index.php/dbcontroller',"_self")
                        }else{
                            alert("Email & Password not match");
                        }
                    },
                    function(response) { // optional
                        $scope.content = "Something went wrong";

                     //   alert( $scope.content);
                    });
    }
});

Cookies CodeIgniter + Angular solving the problem

Set cookie with code igniter controller and get cookie with Angular

PHP / CODEIGNITER



	public function __construct()
	{
		//Core controller constructor
		parent::__construct();
		$this->load->model('registermodel');
		$this->load->helper('cookie');
	}

	public function controller_register(){

		$request= json_decode(file_get_contents('php://input'), TRUE);

		$check = $this->registermodel->model_register($request);


		if($check=="true"){

			$cookie= array(

					'name'   => 'uname',
					'value'  => $request["email"],
					'expire' => '30000'

			);

			$this->input->set_cookie($cookie);

			echo 'true';
		}

	}

JS / ANGULAR


app.controller("dashboardController", function($scope, $http,$cookies) {

if($cookies.get("uname")==null||$cookies.get("uname")==undefined||$cookies.get("uname")==""){
    window.open('http://topzapp.com/index.php/landingcontroller',"_self")
}else{
    $scope.uname = $cookies.get("uname");
}
});