gpt4 book ai didi

javascript - 如何使用 Angular 路线在部分 html 文件中使用 ng-repeat

转载 作者:行者123 更新时间:2023-12-03 11:18:08 26 4
gpt4 key购买 nike

以下代码曾经是我的主 html 文件的一部分,但我决定将应用程序拆分为部分代码,然后渲染它,但我现在陷入困境,不知道如何再重复渲染代码。

<div class="col-md-12" ng-controller="TimeSlotController as calendar" >
<div class="col-md-5 col-md-offset-1 timeblock" ng-repeat="slots in calendar.timeslot" ng-click="calendar.selectTimeSlot(slots.time)">
<h3 class="event-type-name">[[ slots.time]] Hour Appointment</h3>
<div class="description mts">[[slots.description]]</div>
<div class="cost"><i class="fa fa-euro"></i> [[slots.cost ]]</div>
</div>

这就是我的 Controller 现在的样子

app.config(function($interpolateProvider, $routeProvider, $locationProvider) {

$interpolateProvider.startSymbol('[[');
$interpolateProvider.endSymbol(']]');

$routeProvider
.when('/timeslot', {
controller: 'TimeSlotController as timerange',
templateUrl:'/views/timeslot.html'
})
.when('/calendar', {
controller: 'CalendarController',
templateUrl:'/views/calendar.html'
})
.when('/mail', {
controller: "MailController",
templateUrl: '/views/mail.html'
})
.otherwise({
redirecTo: '/timeslot'
});

$locationProvider.html5Mode({
enabled: true,
requireBase: false
});


});


app.controller("TimeSlotController", function($rootScope, $location, $scope) {

$scope.timeslot = [
{
time:1,
description: "Welcome to my scheduling page. Please follow the instructions to add an event to my calendar.",
cost: "10"
},
{
time:2,
description: "Welcome to my scheduling page. Please follow the instructions to add an event to my calendar.",
cost: "20"
},
{
time:4,
description: "Welcome to my scheduling page. Please follow the instructions to add an event to my calendar.",
cost: "10"
},
{
time:6,
description: "Here lies 3",
cost: "10"
}
];

console.log($scope.timeslot);

$scope.selectTimeSlot = function(timeslot) {

$rootScope.timeSlot = timeslot;

console.log($rootScope.timeSlot);

$location.path('/calendar');
}

});

如何在此类文件类型中使用 ng-repeat?我环顾四周,但找不到我要找的东西。

最佳答案

 ng-repeat="slots in timeslot"

骗子:http://plnkr.co/edit/ImdmHlpevzO6FL2fe2EP?p=preview

正如 Dinesh 所说,在指定 Controller 时删除日历。除非您正在做一些我们不知道的更复杂的事情,否则 Angular 足够聪明,可以知道您正在尝试使用哪个 Controller 。

关于javascript - 如何使用 Angular 路线在部分 html 文件中使用 ng-repeat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27239099/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com