The code below has suddenly stopped working. I am receiving a console log error that $scope is undefined. When I pass $scope the console error is gone, but the code is still not working, however 'Page animated!' is displayed in the console window.
.directive('active', function(){
return{
link: function(scope, element, attrs){
$(element).on('click', function(){
console.log('Page animated!');
//addes class to animate page
$scope.elementClass = "my-slide-animation";
});
}
}
});
code with $scope passed
.directive('active', function(){
return{
link: function(scope, element, attrs){
$(element).on('click', function($scope){
console.log('Page animated!');
//addes class to animate page
$scope.elementClass = "my-slide-animation";
});
}
}
});
I've also tried the following:
1.
.directive('active', function($scope){
return{
link: function(scope, element, attrs){
$(element).on('click', function($scope){
console.log('Page animated!');
//addes class to animate page
$scope.elementClass = "my-slide-animation";
});
}
}
});
2.)
//ng-enter and ng-leave animation
.directive('active', function($scope){
return{
link: function($scope, element, attrs){
$(element).on('click', function($scope){
console.log('Page animated!');
//addes class to animate page
$scope.elementClass = "my-slide-animation";
});
}
}
});
3.
//ng-enter and ng-leave animation
.directive('active', function(){
return{
link: function(scope, element, attrs){
$(element).on('click', function(){
console.log('Page animated!');
//addes class to animate page
scope.elementClass = "my-slide-animation";
});
}
}
});
4.
//ng-enter and ng-leave animation
.directive('active', function(){
return{
link: function(scope, element, attrs){
$(element).on('click', function(scope){
console.log('Page animated!');
//addes class to animate page
scope.elementClass = "my-slide-animation";
});
}
}
});
complete app.js
angular.module('myWebsite',['ngRoute', 'duScroll','ngAnimate','headroom'])
.config(function($routeProvider){
$routeProvider
.when('/#', {
templateUrl:'home.html'
})
.when('/about', {
templateUrl:'about.html'
})
.when('/contact',{
templateUrl:'contact.html'
})
.when('/services', {
templateUrl:'services.html'
})
.otherwise({
templateUrl:'home.html'
});
})
.controller('mainCtrl', function($scope, $document)
{
//enables angular-scroll.min.js with dependency of 'duScroll'
$scope.toTheTop = function() {
$document.scrollTopAnimated(0, 2000).then(function() {
console && console.log('You just scrolled to the top!');
})
}
})
//directive for jQuery nivoSlider plugin
.directive('slideit', function(){
return{
link: function(scope, element, attrs){
$(element).nivoSlider();
}
}
})
//ng-enter and ng-leave animation
.directive('active', function(){
return{
link: function(scope, element, attrs){
$(element).on('click', function(){
console.log('Page animated!');
//addes class to animate page
scope.elementClass = "my-slide-animation";
scope.$apply();
});
}
}
});