Showing posts with label Angularjs. Show all posts
Showing posts with label Angularjs. Show all posts
All SESSION Data Print in Angularjs

All SESSION Data Print in Angularjs

Solution 1 :

var app = angular.module('angularjs-starter', []);

app.controller('MainCtrl', function($scope, Session) {
  $scope.name = 'World';
  $scope.session = Session;
});

app.run(function(Session) {}); //bootstrap session;

app.factory('Session', function($http) {
  var Session = {
    data: {},
    saveSession: function() { /* save session data to db */ },
    updateSession: function() {
      /* load data from db */
      $http.get('session.json')
        .then(function(r) { return Session.data = r.data;})
    }
  };
  Session.updateSession();
  return Session;
});

session.json
------------
{
  "username": "John Smith"
}

HTML PART
----------------

<body ng-controller="MainCtrl">
    <h1>Hello {{name}}</h1>
    Session object:
    <pre ng-bind='session.data | json'></pre>
 </body>
How to Write data to file in angularJS

How to Write data to file in angularJS

index.html
----------
<div ng-controller="MyCtrl">
  <input type="file" id="fileid" name="fileid"/>
  <br>
  <button ng-click="addfile()">Add_Button</button>
  <p>{{myfilecontent}}</p>
</div>


App.js
------
var myApp = angular.module('myApp',[]);

function MyCtrl($scope) {
    $scope.myfilecontent = 'Here....';
    $scope.addfile = function(){
      var f = document.getElementById('fileid').files[0],
          r = new FileReader();
      r.onloadend = function(e){
        $scope.myfilecontent = e.target.result;
      }
      r.readAsBinaryString(f);
    }
}

angularjs with php

 
php with angularjs

index.html

<!-- Learn AngularJS-->
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>

 <div ng-app="myApp" ng-controller="customersCtrl">

<table border="2">
  <tr ng-repeat="x in names">
    <td>{{ x.First }}</td>
    <td>{{ x.Last_Name }}</td>
     <td>{{ x.Email }}</td>
  </tr>
</table>

</div>

<script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
    $http.get("customers_mysql.php")
    .then(function (response) {
    console.log(response);
    $scope.names = response.data.records;
    });
});
</script>

</body>
</html>

customers_mysql.php

<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
$conn = new mysqli("localhost", "root", "", "mydatabase");
$result = $conn->query("SELECT *  FROM contacts");
$outp = "";
while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
    if ($outp != "") {$outp .= ",";}
    $outp .= '{"First":"'  . $rs["contact_first"] . '",';
    $outp .= '"Last_Name":"'   . $rs["contact_last"]        . '",';
    $outp .= '"Email":"'. $rs["contact_email"]     . '"}';
}
$outp ='{"records":['.$outp.']}';
$conn->close();
echo($outp);
?>
php with angularjs

Learn AngularJS

<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="">
        <p>Please Enter Your name:</p>
        <p>Name: <input type="text" ng-model="myname"></p>
         <p ng-bind="myname">Wel-come :</p>
         Welcome {{myname}}
</div>
</body>
</html>

Kategori

Kategori