我有一个非常简单的应用程序,它具有两个功能。第一,列出所有键,第二,应该显示一个特定键(和关联的值)。
这是列出密钥的第一部分:
var app = angular.module('flipDaSwitch', ['ngRoute']);
app.controller('ListKeys', function($scope, $http) {
$scope.getKeys = function() {
$http.get('/api/keys').
success(function (data) {
$scope.buckets = data;
}).
error(function (data){
$scope.buckets = {}
});
};
});
我想知道如何从API中获取特定的密钥。当前的HTML:
<div name="listkeys" class="container">
<div class="starter-template">
<div ng-bind-html="message"></div>
<table class="table table-striped table-bordered table-condensed sortable" ng-init="getKeys()">
<tr>
<th>Bucket:</th>
</tr>
<tr ng-repeat="bucket in buckets">
<td>
<a ng-href="/show_key.html#/key/{{bucket}}">{{bucket}}</a>
</td>
</tr>
</table>
</div>
</div>
显然,show_key.html可以通过以下方式获取URL中的密钥:
/show_key.html#/key/efd1ae55a5-random_string
我不确定如何根据URL参数发出get请求。
注入$routeParams
控制器:
app.controller('ListKeys', function($scope, $http, $routeParams) {
...
关于此还有很多问题。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句