我正在尝试通过第一个单击来更新第二个指令中的内容。这是某种类型的范围界定问题吗?我主要从引导轮播中获取代码。https://github.com/angular-ui/bootstrap/tree/master/src/carousel
我有票和票图标。我希望在单击图标时显示相应的票证。模型当前有 {name: 'name', type: 'home'}。
两个指令ticketicons和tickets被调用:
<body>
<div ng-controller="TicketSwipeCtrl">
<!-- for itinerary in itineraries -->
<ticketicons></ticketicons>
<ticket></ticket>
预期的结果是,当单击第二个项目符号时,名称 - AQVVMF.htm 更改为 NWMMRE.htm。javascript 控制台会打印出事件。
完整的示例代码是:
var clickTest = angular.module('clickTest', ['interlated.ticketSwipeTest', 'template/travelbytes/iconbar.html']);
function TestClickCtrl($scope) {
}
angular.module("template/travelbytes/iconbar.html", []).run(["$templateCache", function($templateCache) {
$templateCache.put("template/travelbytes/iconbar.html",
"<div ng-mouseenter=\"pause()\" ng-mouseleave=\"play()\" class=\"carousel\">\n" +
"<h2>Icon Row {{tickets().length}}</h2>\n" +
" <ul class=\"nav-swipe pull-left text-center\" ng-show=\"tickets().length > 1\">\n" +
" <li ng-repeat=\"ticket in tickets()\" <i ng-click=\"select(ticket)\" class=\"icon-{{ticket.type}}\"></i></li>\n" +
" </ol>\n" +
"</div>\n" +
"");
}]);
var ticketSlideModule = angular.module('interlated.ticketSwipeTest', ['ui.bootstrap.transition', "template/travelbytes/iconbar.html"])
.controller('TicketSwipeTest', ['$scope', '$timeout', '$transition', '$q', '$log', '$http',
function($scope, $timeout, $transition, $q, $log, $http) {
var self = this;
self.log = $log;
var tickets =
[{name: 'AQVVMF.htm', type: 'road'}, {name: 'NWMMRE.htm', type: 'home'}];
var currentTicket = $scope.$currentTicket = tickets[0];
self.select = function(ticket, direction) {
var nextIndex = tickets.indexOf(ticket);
currentTicket = ticket;
};
$scope.currentTicket = function() {
$log.log('currentTicket: %s', currentTicket.name);
return currentTicket;
}
$scope.tickets = function() {
return tickets;
}
}]);
ticketSlideModule.directive('ticketicons', [function() {
var directiveDefinitionObject = {
restrict: 'EA',
transclude: true,
replace: true,
controller: 'TicketSwipeTest',
require: 'ticketSwipeTest',
templateUrl: 'template/travelbytes/iconbar.html',
};
return directiveDefinitionObject;
}])
ticketSlideModule.directive('ticket', ['$parse', function($parse) {
return {
require: 'interlated.ticketCarousel',
controller: 'TicketSwipeTest',
restrict: 'EA',
transclude: true,
replace: true,
template: '<div>{{currentTicket().name}} test</div>',
scope: {
}};
}]);