這是我的JS文件有兩個NG-控制器angularJS
var camListApp = angular.module('camListApp', []);
camListApp.controller('Hello', ['$scope', '$http', function($scope, $http){
$http.get('http://localhost:8080/camera/list').then(function(response) {
$scope.records= response.data;
});
}]);
camListApp.controller('Hello2',['$scope', function($scope){
$scope.custom = true;
$scope.toggleCustom = function() {
$scope.custom = ! $scope.custom;
};
}]);
這是我的HTML文件
<html ng-app='camListApp'>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js">
</script>
<script src="hello.js"></script>
<title>Image downloader </title>
</head>
<body>
<h3>Search by cameraid:</h3><br>
<select ng-model="searchBox" style="width:25%">
<option value="000000006f4280af">000000006f4280af</option>
<option value="002">002</option>
<option value="0011">0011</option>
</select>
<div ng-controller="Hello">
<br>
<table>
<thead>
<tr>
<th>CamID</th>
<th>Timestamp</th>
<th>View Image</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="record in records | filter:searchBox">
<td>{{record.cameraid}}</td>
<td>{{record.timestamp}}</td>
<div ng-controller="Hello2">
<td><button ng-click="toggleCustom()">View</button></td>
</tr>
</tbody>
</table>
<span ng-hide="custom">From:
<input type="text" id="from" />
</span>
<span ng-show="custom"></span>
</div>
</body>
</html>
我怎麼能有兩個控制器在應用中的工作?因爲我無法找到任何方式讓他們同時工作。第一個控制器是使用angularjs來使用我的web服務,但是這能夠工作,並且我添加了另一個使用切換按鈕來顯示和隱藏的控制器。
'div'不在'tr'一個有效的元素。另外,有沒有任何控制檯錯誤? – devqon
像@devqon寫道,你的HTML是無效的,你甚至不關閉你的div與ng-controller – kTT
所以我應該把div放在哪裏? –