我正在为我正在构建的应用程序使用AngularJS,并且想知道当条目被推送到一个名为places的JSON对象时,是否有可能生成页面。推送的每个项目都有一个唯一的ID,我想我可以使用这个id (例如123456)作为url的一部分,比如so site.com/places/123456。
{
"places" : [
{
"id" : 471756,
"title" : "The Whittington Hospital"
}
]
}是否可以自动生成此页面(例如,基于模板)?
我之所以问这个问题,是因为我正试图构建一个应用程序,让用户通过表单创建自己的医院。一旦创建了一个医院并将其推送到JSON对象,我希望为该医院创建一个页面。
我能用角做这个吗?任何帮助都是非常感谢的。
提前感谢!
更新
还是有点麻烦。这是我到目前为止所得到的。
place.html
<div ng-controller='PlaceCtrl'>
<h1>{{ title }}</h1>
</div>JS
app.constant('FBURL', 'https://luminous-fire-8685.firebaseio.com/');
app.config(['$routeProvider', function ($routeProvider) {
$routeProvider
.when('/places/:placeId', {
templateUrl: 'views/place.html',
controller: 'PlaceCtrl'
})
}]);
app.factory('place', function($firebase, FBURL, $routeParams) {
var ref = new Firebase(FBURL + "places/" + $routeParams.placeId);
return {
id: $routeParams.placeId
}
});
app.controller('PlaceCtrl', function($scope, $rootScope, FBURL, $firebase, $location, $routeParams, place) {
$scope.placeId = place.id;
});发布于 2014-10-31 19:52:26
你在找ngRoute和$routeProvider。使用这些选项,您可以设置如下参数化路由:
.when('/place/:placeId', { templateUrl: 'place.html', controller: 'PlaceCtrl' })因此,每次访问者访问以/place/开头的URL时,都会以PlaceCtrl和place.html结束。并将place作为参数传递。
然后,您可以在控制器中获取参数:
app.controller('PlaceCtrl', function($scope, FBURL, $firebase, $routeParams) {
var ref = new Firebase(FBURL+"places/"+$routeParams.placeId); 另请参阅:
routeParamshttps://stackoverflow.com/questions/26678948
复制相似问题