2014-09-18 5 views
0

я есть показать данные телефона на сайте вид:как автоматически обновлять данные о представлении в angular.js

<table class="table table-stripes data-tables" ng-controller="GetData as mydata"> 
      <tr> 
       <th align="center"><div align="center">S.#</div></th> 
       <th align="center"><div align="center">Name</div></th> 
       <th align="center"><div align="center">Number</div></th> 
       <th align="center"><div align="center">Edit</div></th> 
       <th align="center"><div align="center">Delete</div></th> 
      </tr> 
      <tr ng-repeat="alldata in mydata.row | filter:search "> 
       <td>{{alldata.id}}</td> 
       <td>{{alldata.name}}</td> 
       <td>{{alldata.numbers}}</td> 
       <td><button class="btn btn-primary">Edit</button></td> 
       <td><button class="btn btn-danger">Delete</button></td> 
      </tr> 
     </table> 

и когда пользователь добавить новый я хочу, чтобы обновить контроллер. как я могу это сделать

//getdata controller 


myApp.controller("GetData",['$http','$log','$location','$timeout', function($http,$log,$location,$timeout){ 
var ata = this; 
ata.row = [ ] ; 
$http({method: 'POST', url: 'process/getdata.php'}) 
.success(function(data) { 
    // this callback will be called asynchronously 
    // when the response is available 
// $log.log(data); 
ata.row=data; 
    }). 
    error(function(data, status, headers, config) { 
    // called asynchronously if an error occurs 
    // or server returns response with an error status. 
    }); 
}]); 

// add new item controller 



myApp.controller("addNumber",['$http','$log','transformRequestAsFormPost','$location', function($http,$log,transformRequestAsFormPost,$location){ 

    this.add = function(name,number){ 

    var mydata='name='+name+'&number'+number; 
     $http({ 
      method: 'POST', 
      url: 'process/addnumbers.php', 
      data:{ 
       name: name, 
       number: number 
      }}). 
    success(function(data, status, headers, config) { 
    // this callback will be called asynchronously 
    // when the response is available 
    $log.log(data); 
    if(data == 'true') 
    { 

    } 
    else 
    { 

    } 

    }). 
    error(function(data, status, headers, config) { 
    // called asynchronously if an error occurs 
    // or server returns response with an error status. 
    }); 
    } 
}]); 
  • , что я должен делать с контроллером GetData
  • , что я должен делать, когда пользователь добавить новую запись

ответ

0

попробуйте обновить страницу в контроллере добавить номер. это может быть помощь.

myApp.controller("addNumber",['$http','$log','transformRequestAsFormPost','$location','$route', function($http,$log,transformRequestAsFormPost,$location,$route){ 

    this.add = function(name,number){ 

    var mydata='name='+name+'&number'+number; 
     $http({ 
      method: 'POST', 
      url: 'process/addnumbers.php', 
      data:{ 
       name: name, 
       number: number 
      }}). 
    success(function(data, status, headers, config) { 
    // this callback will be called asynchronously 
    // when the response is available 
    $log.log(data); 
    if(data == 'true') 
    { 

     $route.reload(); 
     // get the current path 
     $location.path(); 

     // change the path 
     $location.path('/Dashboard'); 

    } 
    else 
    { 

    } 

    }). 
    error(function(data, status, headers, config) { 
    // called asynchronously if an error occurs 
    // or server returns response with an error status. 
    }); 
    } 
}]); 

инъекционные $route службы в контроллере

Смежные вопросы