我正在尝试使用Angularjs.问题是,ng-repeat在路线中不起作用.它不在路线时工作.
这是我到目前为止所拥有的:
看到链接..
这效果很好……
http://plnkr.co/edit/1syQFJdMyRUYncBrREue?p=preview
但在此,它现在不起作用..(导航人)
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>
角
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;
};
}]);
解决方法:
这是(有点)fixed plunker,但是我在你的代码中发现了以下问题:
>你有双控制器:loglistController定义两次,一次在app.js内,然后再在list.html内.
你写了以下这一行
< tr ng-repeat =“x in data”>
认为它会从loglistController的$scope.data读取,但您的应用程序似乎正在考虑第一个控制器,因此您的控制器范围没有数据属性.我解决了用app.html里面的一个替换app.js中的控制器.
考虑一下,我猜你不允许在它的模板中放置一个路由控制器的代码,所以你最好避免在将来这样做!
>当url为’/’时,你的app.js’templateUrl不存在,这会引发错误.我用’list.html’替换它解决了.我很确定这不是你想要的东西,但它需要让它发挥作用.