Angular does not display data in a table row. ng-repeat does not work

I am trying to use Angularjs. The problem is that ng-repeat does not work when it is on the route. It works when it is not in transit.

Here is what I still have: See links ..

this works well ... http://plnkr.co/edit/1syQFJdMyRUYncBrREue?p=preview

but he didn’t work in this now .. (navigate through faces) http://plnkr.co/edit/gsi2mZpnU0YJUUOa20DO?p=preview

HTML

<html ng-app="myApp">
<head>
    <title>Confirm Dialog Box</title>
 <!-- 
    in the link above i create a custom dialog box
 -->
</head>
<body>

<div ng-controller="loglistController">
<table>
  <tr ng-repeat="x in names">
    <td onclick="showDialog()" ng-click="showInEdit(x)">{{ x.Name }}</td>
    <td onclick="showDialog()" ng-click="showInEdit(x)">{{ x.Country }}</td>
  </tr>
</table>


             <div id="white-background">
</div>
<div id="dlgbox">
    <div id="dlg-header"><h3>Information</h3></div>
    <div id="dlg-body">
      Name <input type="text" ng-model="selectedPerson.Name" /><br/>
      Country <input type="text" ng-model="selectedPerson.Country" /><br/>


    </div>
    <div id="dlg-footer">
        <button onclick="dlgOK()">Update</button>
        <button onclick="dlgCancel()">Exit</button>
    </div>
</div>

angular

var myApp = angular.module('myApp', ['ngRoute']);

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

    $scope.data=[];
    $scope.selectedPerson={ Name:"",Country:""}; 

            $http.get("loglistajax.php")
                .then(function (response) {$scope.names = response.data.records;});

    $scope.showInEdit=function(person){
    $scope.selectedPerson = person;
    };



 }]);
+4
source share
3 answers

Here is a (somewhat) fixed plunker , however I found the following problems in your code:

  • : loglistController , app.js, list.html.

    <tr ng-repeat="x in data">

    , loglistController $scope.data, , , , . app.js list.html.

    , , , !

  • app.js 'templateUrl , url '/', . , 'list.html'. , , , , .

+1

, imbalind.

:

  • ( Plunker index.html, list.html). :

    var myApp = angular.module('myApp', ['ngRoute']); //new instance of 'myApp' 
    
    var myApp = angular.module('myApp'); //simply handle to 'myApp'
    
  • 'loglistController', angular.module,

  • angular html, .

  • Plunker, app.js:

    .when('/', {
        templateUrl: '/index.html',
        controller: 'mainController'
    })
    
  • , , jQuery script, ...

+2

, $http ?

 $http.get("loglistajax.php").then(function (response) {
     $scope.names = response.data.records;
 }).catch(function(response) {
     console.log("I am failing to resolve a non-2xx response");
 });

$http n !

FYI...

...

$scope.names = $http.get("loglistajax.php");

HTTP-!

PS plunkr !

0
source

Source: https://habr.com/ru/post/1620791/


All Articles