OK I'm loading a template into a ng-include like so:
<about ng-click="loadpantone()"></about>
<div class="pantone_wrapper">
<div ng-include="template" tabindex="0" id="focus_force" ng-keydown="keypress($event.keyCode)" ng-class="PrevNext" class="pantoneani remo pantonebg blue" ></div>
</div>
directive about:
'use strict';
/*global $:false */
angular.module('bawdApp')
.directive('about', function () {
return {
templateUrl: 'views/pantone-inner.html',
restrict: 'AE',
link: function postLink($scope, element) {
function border(valueWidth){
$('.page_cont_wrap').css('border', valueWidth+'px solid #aaFFFF');
}
$(element).css({'position': 'absolute'}).delay(200).animate({
'margin-left': '-160px',
'margin-top': '-233px',
'left': '50%',
'top': '50%'
}, 200);
$scope.loadpantone = function loadpantone(){
border(0);
$scope.template = $scope.pantonesAbout[0].url;
$('.top_left_logo.white img').css('position', 'fixed');
};
}
};
});
directive that then deals with the content in the ng-include loaded content:
'use strict';
/*global $:false */
angular.module('bawdApp')
.directive('pantoneMenu', function () {
return {
templateUrl: 'views/pantone_menu.html',
restrict: 'AE',
transclude: true,
link: function($scope, $document) {
var arraylength = $scope.pantonesAbout.length;
function next(){
$scope.$parent.pantoneconter = $scope.$parent.pantoneconter + 1;
$scope.$parent.PrevNext = 'next';
if($scope.$parent.pantoneconter >= arraylength){
$scope.$parent.pantoneconter = 0;
$scope.$parent.template = $scope.pantonesAbout[$scope.$parent.pantoneconter].url;
}else{
$scope.$parent.template = $scope.pantonesAbout[$scope.$parent.pantoneconter].url;
}
}
function prev(){
var arraylength = $scope.pantonesAbout.length;
$scope.$parent.pantoneconter --;
$scope.$parent.PrevNext = 'prev';
if($scope.$parent.pantoneconter >= arraylength){
$scope.$parent.pantoneconter = 0;
$scope.$parent.template = $scope.pantonesAbout[$scope.$parent.pantoneconter].url;
}else if ($scope.$parent.pantoneconter < 0){
$scope.$parent.pantoneconter = arraylength -1;
$scope.$parent.template = $scope.pantonesAbout[arraylength - 1].url;
}
else{
$scope.$parent.template = $scope.pantonesAbout[$scope.$parent.pantoneconter].url;
}
}
$scope.close = function close(){
$scope.$parent.template = '';
$('.remo').addClass('pantoneani');
$('.top_left_logo.white img').css('position', 'relative');
};
$scope.nextpro = function nextpro(){
next();
};
$scope.prevpro = function prevpro(){
prev();
};
/* $(document).on('keyup',function(e){
function plusone(){
$scope.$parent.pantoneconter = $scope.$parent.pantoneconter + 1;
}
if(e.which === 37){
$scope.$apply(function () {
var arraylength = $scope.pantonesAbout.length;
$scope.$parent.pantoneconter --;
$scope.$parent.PrevNext = 'prev';
if($scope.$parent.pantoneconter >= arraylength){
$scope.$parent.pantoneconter = 0;
$scope.$parent.template = $scope.pantonesAbout[$scope.$parent.pantoneconter].url;
}else if ($scope.$parent.pantoneconter < 0){
$scope.$parent.pantoneconter = arraylength -1;
$scope.$parent.template = $scope.pantonesAbout[arraylength - 1].url;
}
else{
$scope.$parent.template = $scope.pantonesAbout[$scope.$parent.pantoneconter].url;
}
});
}
if(e.which === 39){
$scope.$apply(function () {
plusone();
$scope.$parent.PrevNext = 'next';
if($scope.$parent.pantoneconter >= arraylength){
$scope.$parent.pantoneconter = 0;
$scope.$parent.template = $scope.pantonesAbout[$scope.$parent.pantoneconter].url;
}else{
$scope.$parent.template = $scope.pantonesAbout[$scope.$parent.pantoneconter].url;
}
});
}
});*/
}
};
});
about controller:
'use strict';
angular.module('bawdApp')
.controller('AboutCtrl', function ($scope) {
$scope.pantonesAbout = [
{name:'Pantone intro', url:'views/pantone_about.html'},
{name:'Pantone one', url:'views/about_patone_one.html'},
{name:'Pantone two', url:'views/about_patone_two.html'},
{name:'Pantone three', url:'views/about_patone_three.html'},
{name:'Pantone four', url:'views/about_patone_four.html'},
{name:'Pantone five', url:'views/about_patone_five.html'},
];
$scope.pantoneconter = 0;
});
loaded content includes: pantone_menu.html
<section>
<div tabindex="0" id="focus_force" ng-keydown="keypress($event.keyCode)"> prev next!</div>
<header>
<a ng-href="#" class="top_left_logo white"><img src="images/logo_white.png" alt="BAWD Logo"></a>
<p ng-click="close()">close</p>
</header>
<div ng-click="prevpro()"><p>prev</p></div>
<div ng-click="nextpro()"><p>next</p></div>
</section>
I have been fighting all day with ng-keydown I need it to load into the pantone_menu.html directive and have the user be able to click left or right and it then to work the same as prev and next the only way I've been able to do it currently is using jquerylite like so:
$(document).on('keyup',function(e){
function plusone(){
$scope.$parent.pantoneconter = $scope.$parent.pantoneconter + 1;
}
if(e.which === 37){
$scope.$apply(function () {
var arraylength = $scope.pantonesAbout.length;
$scope.$parent.pantoneconter --;
$scope.$parent.PrevNext = 'prev';
if($scope.$parent.pantoneconter >= arraylength){
$scope.$parent.pantoneconter = 0;
$scope.$parent.template = $scope.pantonesAbout[$scope.$parent.pantoneconter].url;
}else if ($scope.$parent.pantoneconter < 0){
$scope.$parent.pantoneconter = arraylength -1;
$scope.$parent.template = $scope.pantonesAbout[arraylength - 1].url;
}
else{
$scope.$parent.template = $scope.pantonesAbout[$scope.$parent.pantoneconter].url;
}
});
}
if(e.which === 39){
$scope.$apply(function () {
plusone();
$scope.$parent.PrevNext = 'next';
if($scope.$parent.pantoneconter >= arraylength){
$scope.$parent.pantoneconter = 0;
$scope.$parent.template = $scope.pantonesAbout[$scope.$parent.pantoneconter].url;
}else{
$scope.$parent.template = $scope.pantonesAbout[$scope.$parent.pantoneconter].url;
}
});
}
});
but I really want to be able to do it via angularJS I've tried using tabindex="0" in my pantone menu and this then works when i actually click the element it focuses and I can get it to console.log: in pantone_menu.html: prev next!
pantone_menu directive:
$scope.keypress = function keypress(){
console.log('keyCode');
};
Now this works but only when i focus(I.E click on the element) I need it to work as soon as the pantone_menu loads.. how? this is driving me nuts! Note: I'm loading angularJS-ui aswell but no luck... as asked plnkr As you can see if you un-comment out line 79 to 112 it will work buut it then erros on one of the scopes and it just seems wrong to do it like this?