How to pass data from one page to other page in angular js

Rahul Saxena

I have created a new blog project using angular-js. Here I have one page listing all the blogs and if I click on the edit button or delete button, I want to move to next page and show that data in the form from where I updated the blog.

My blog list page: listblog.html

<!DOCTYPE html>
<html lang="en">

<head>



    <title>My First AngularJs Blog</title>

 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>

    <!-- Bootstrap Core CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="css/blog-home.css" rel="stylesheet">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>

<body ng-app="blogapp">

    <!-- Navigation -->
   <div ng-include="'includes/header.html'">                    
</div>

    <!-- Page Content -->



       <div class="container">
 <div ng-controller="blogcontroller">
  <h2>Blog List</h2>
  <p>Here is the awsome blog list</p>            
  <table class="table">
    <thead>
      <tr>
        <th>Title</th>
        <th>Blog</th>
        <th>Posted On</th>
        <th>Action</th>
      </tr>
    </thead>
    <tbody>
      <tr  ng-repeat="blg in allblog">
        <td>{{blg.title}}</td>
        <td>{{blg.description}}</td>
        <td>{{blg.created_on }}</td>
        <td><a href="">Edit</a> || <a href="">Delete</a></td>
      </tr>

    </tbody>
  </table>

  </div>
</div>


        <hr>

        <!-- Footer -->

 <div ng-include="'includes/footer.html'">                    
</div>

    <!-- /.container -->

    <!-- jQuery -->
    <script src="js/jquery.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="js/bootstrap.min.js"></script>
<script src="controller.js"></script>
</body>

</html>

I want to create a controller for edit. My Controller file: controller.js

var myApp = angular.module("blogapp", []);

  myApp.controller('blogcontroller',function ($scope,$http){

    $http({method: 'GET' , url: 'getallblog.php'}).success(function(data){
        $scope.allblog = data;
    });


    $scope.new_post =function(){



    $http.post("addblog.php" ,{'title' : $scope.title ,'description' : $scope.description }).success(function(data,status,headers,config){
        window.location='index.html';
        console.log("inserted Successfully");
    });
  } ;


  $scope.editpost = function(index){

    $http.post('allscript.php?action=edit_post', { 'id' : index})
    .success(function (data, status, headers, config){


    }) 
    .error(function (data, status, headers, config){
           console.log(status);
        });


  }

  });

And my php script page where all operations are performed allscript.php

<?php 

$user ="root";
$pass ="m2n1shlko";

$dbh = new PDO('mysql:host=localhost;dbname=blog_db', $user, $pass);


switch($_GET['action']){

    case 'edit_post':
        edit_post();
    break;





function edit_post(){

  $data = json_decode(file_get_contents("php://input"));     
    $index = $data->id; 

$query = $dbh->prepare("SELECT * FROM blog_list where id='$index'") ;
$da = $query->execute();
$getre = $da->fetch(PDO::FETCH_ASSOC);

print_r(json_encode($getre));
return $getre;


}



}
?>

I am new in angular-js. I don't know how to get the ID of that record and to take to the next page for edit/update/delete.

Any help is appreciated. Thanks.

Fire Bull

Actually the @Jeremy Thille is right... Please check angular ngRoute module for more info https://docs.angularjs.org/tutorial/step_07.
Also the good practice is to refactor all of your connections/post/get in factories/services, and to inject them directly on your controllers (where you needs of them) http://viralpatel.net/blogs/angularjs-service-factory-tutorial/

Good luck.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to pass data from one page to other page in angular js

From Dev

how to pass array Data one-Page to other page

From Dev

How to pass Array of JSON Data from one html page to other html page?

From Dev

How to pass Array of JSON Data from one html page to other html page?

From Dev

How to pass data from one page to another in single page application in angular

From Dev

how to pass the value from one page to another page in angular?

From Dev

How to pass data from one page to another page html

From Dev

How to pass data from one page to another page in python tkinter?

From Dev

Sending Data From One Page To The Other Page

From Dev

How to pass data from one html page to another using javascript?

From Dev

How To Pass Form Data from One Page To Another using FlaskApp

From Dev

How to pass model class data from one page another in iOS?

From Dev

Passing data from one page to another in angular js

From Dev

How to get data from one php page using ajax and pass it to another php page using ajax

From Dev

How to send data from one page to other page in php when the user clicks on the displaying value as said below

From Dev

How to pass form fields from one page to another page in ReactJS?

From Dev

how to pass the value from one page to another page in html

From Dev

how to pass values from one page to another then further to third page

From Dev

JQuery Mobile :how to call panel in one page from the other page

From Dev

JQuery Mobile :how to call panel in one page from the other page

From Dev

How to pass the data obtained from the PHP page on the server's local page in JS?

From Dev

how to pass $db->insert_id from one form to other on the same page

From Dev

How to pass error array from one php file to other and display errors on top of the page?

From Dev

How to pass error array from one php file to other and display errors on top of the page?

From Dev

How pass data from parent page to popup?

From Dev

How to pass data from a html page to another?

From Dev

How pass data from parent page to popup?

From Dev

How at other way transfer the message from one PHP page to other?

From Java

How to send result data from one page to another page in React

Related Related

  1. 1

    How to pass data from one page to other page in angular js

  2. 2

    how to pass array Data one-Page to other page

  3. 3

    How to pass Array of JSON Data from one html page to other html page?

  4. 4

    How to pass Array of JSON Data from one html page to other html page?

  5. 5

    How to pass data from one page to another in single page application in angular

  6. 6

    how to pass the value from one page to another page in angular?

  7. 7

    How to pass data from one page to another page html

  8. 8

    How to pass data from one page to another page in python tkinter?

  9. 9

    Sending Data From One Page To The Other Page

  10. 10

    How to pass data from one html page to another using javascript?

  11. 11

    How To Pass Form Data from One Page To Another using FlaskApp

  12. 12

    How to pass model class data from one page another in iOS?

  13. 13

    Passing data from one page to another in angular js

  14. 14

    How to get data from one php page using ajax and pass it to another php page using ajax

  15. 15

    How to send data from one page to other page in php when the user clicks on the displaying value as said below

  16. 16

    How to pass form fields from one page to another page in ReactJS?

  17. 17

    how to pass the value from one page to another page in html

  18. 18

    how to pass values from one page to another then further to third page

  19. 19

    JQuery Mobile :how to call panel in one page from the other page

  20. 20

    JQuery Mobile :how to call panel in one page from the other page

  21. 21

    How to pass the data obtained from the PHP page on the server's local page in JS?

  22. 22

    how to pass $db->insert_id from one form to other on the same page

  23. 23

    How to pass error array from one php file to other and display errors on top of the page?

  24. 24

    How to pass error array from one php file to other and display errors on top of the page?

  25. 25

    How pass data from parent page to popup?

  26. 26

    How to pass data from a html page to another?

  27. 27

    How pass data from parent page to popup?

  28. 28

    How at other way transfer the message from one PHP page to other?

  29. 29

    How to send result data from one page to another page in React

HotTag

Archive