【发布时间】:2016-06-14 21:08:50
【问题描述】:
这是我的 JS 文件
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 写的,你的html 是无效的,你甚至没有用ng-controller 关闭你的div
-
那么我应该把 div 放在哪里?
-
丢掉这个div,比如把
ng-controller放在td上面 -
我关闭但仍然无法工作。 @kTT
标签: javascript angularjs