我正在使用ng-repeat创建一些div。
见下面的代码:
.controller('meditationsController', function ($scope, $state, $rootScope, $http) {
var req = {
method: 'POST',
url: 'http://example.com/demo/',
headers: {
'Content-Type': 'application/json'
}
}
// Call API
$http(req).then(function(result) {
var rawData = result.data;
$scope.meditationByCategory = {};
for (var i = 0; i < rawData.length; i++) {
var meditation = rawData[i];
if ($scope.meditationByCategory[meditation.main_title] == undefined) {
$scope.meditationByCategory[meditation.main_title] = {};
$scope.meditationByCategory[meditation.main_title].name = meditation.main_title;
$scope.meditationByCategory[meditation.main_title].meditations = [];
}
$scope.meditationByCategory[meditation.main_title].meditations.push(meditation);
}
});
})
<div ng-repeat="(categoryName, category) in meditationByCategory">
<div class="peacefulness"><p class="para-text">{{category.name}}</p></div>
<a href="" ng-click="goToDetailPage()" class="customlink">
<div class="item-content" ng-repeat="meditation in category.meditations">
<span class="leftSpanStyle">{{meditation.title}}</span>
<span class="rightSpanStyle">
<i class="icon ion-ios-information-outline icon-size"></i>
</span>
</div>
</a>
</div>
我已根据服务响应动态创建了div列表。
现在我想对每个div应用click。我在服务响应中获得的数据想要绑定下一页。我的意思是下一页的数据将是动态的,取决于cliked div。
请帮我将数据绑定到另一个页面..
答案 0 :(得分:0)
在视图中添加一个按钮。类似的东西:
<!--FORM NR 1-->
<form action="http://localhost/wordpress/restock/myDbMod/" method="post">
<table>
<caption>Sales</caption>
<tr>
<td><select name='tvs'>
<?php
foreach ($tvs as $tv) {
printf("<option value='%s'>%s inch, in stock: %s</option>\n"
, $tv->getScreenSize()
, $tv->getScreenSize()
, $tv->getStockLevel());
}
?>
</select></td>
<td><input type='text' name='tvno'/></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Send"/></td>
</tr>
</table>
</form>
<!--FORM NR 2-->
<form action="http://localhost/wordpress/restock/myDbMod/" method="post">
<table>
<?php
foreach ($tvs as $tv) {
printf("<tr><td name='tvs' value='%s'>%s inch, in stock: %s</td><td><input type='text' name='tvno'/></td>\n"
, $tv->getScreenSize()
, $tv->getScreenSize()
, $tv->getStockLevel());
}
?>
<td><input type="submit" value="Send"/></td></tr>
</table>
</form>
在你的控制器中:
<span class="rightSpanStyle">
<i class="icon ion-ios-information-outline icon-size"></i>
</span>
<button ng-click="doSomeThing($index)"></button>
修改强>
正如您所说“想要绑定到下一页”我假设您要导航到另一个页面。假设你使用角度ui-router这样做,这意味着你想要改变状态。在这种情况下,不要忘记定义:
$scope.doSomeThing = function(index){
//do something with category.meditations[index]
//or go to another state: $state.go("myState", {item: category.meditations[index]})
}
对于那个州有问题。您可以使用url: /myUrl/:item