0
我希望将templateUrl
的页面route
指向wizard.html
页面。要将固定项目过滤到其各自的页面,例如,我使用:| filterBy: ['href']:'/sound-waves'
。如何动态地在一个页面上插入项目?如何在一页上动态插入数组中的项目
angular.module('tareasApp')
.controller('NatureCtrl', function ($scope, $routeParams, $sce, $location, $anchorScroll) {
$scope.items =[
{
href:'/sound-waves',
img:'waves.jpg',
video:'//www.youtube.com/watch?v=OG2eGVt6v2o',
description:'Those Relaxing Sounds of Waves'
},
{
href:'/nature-relaxing-sound',
img:'ocean.jpg',
video:'//www.youtube.com/watch?v=SWR0GdC7_40',
description:'Nature Sounds Relaxing Ocean Sounds'
}
];
});
页wizard.html
<div ng-controller="NatureCtrl">
<div ng-repeat="item in items | filterBy: ['href']: ''" >
<img ng-src="images/{{ item.img }}" width="400" height="200" >
<p>{{item.description}}</p>
<iframe width="655" height="400" ng-src="{{ item.video }}" frameborder="0" allowfullscreen></iframe>
</div>
</div>
路线
angular.module('tareasApp')
.config(function ($routeProvider, $locationProvider) {
$locationProvider.html5Mode(true);
$routeProvider
.when('/sound-waves', {
templateUrl: 'views/wizard.html',
controller: 'NatureCtrl'
})
.when('/nature-relaxing-sound', {
templateUrl: 'views/wizard.html',
controller: 'NatureCtrl'
})
.otherwise({
redirectTo: '/'
});
});
的目标是避免具有相同的结构的多个页面。
编辑:页面的名称不是按顺序排列,所以不是。我已经让它更容易理解。 (写为:头版,页二改为声波产生,自然放松的声音)
编辑:把...controller('NatureCtrl', function...
涉及项目阵列更好的理解。
页面的名称不是按顺序排列,所以不是。我已经让它更容易理解,路线的设置也是如此? – 2015-02-24 15:38:31
@ThiagoJem,很好 - 我更新了答案 – 2015-02-24 15:44:09
优化的路径参数更加实用,除了我在每条路线上都有一个标题,并且现在不知道如何拥有页面标题。 – 2015-02-24 16:46:05