2

Is there a way to call a jQuery function only in a certain Angularjs controller/view? For example, I want to call the slides function only in the home view.

Slides:

$('.slides').superslides();

app.js:

var myApp = angular.module('myApp', ['ngRoute']);
myApp.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
$routeProvider
.when('/', {
     templateUrl : 'views/home.html',
     controller  : 'mainController'
 });

 $locationProvider.html5Mode(true).hashPrefix('!');

 }]);

 myApp.controller('mainController', function($scope, $location, $anchorScroll) {
   $scope.scrollTo = function(id) {
   $location.hash(id);
   $anchorScroll();
  }
 });
0

1 Answer 1

3

Create a directive.

JS:

 myApp.directive( "superslides",
        function()
        {
            return {
                restrict: "A",
                scope: {},
                link: function ( scope, element, attrs )
                {
                    $( element ).superslides();
                }
            }
        }
    )

html:

<ul superslides>
</ul>
Sign up to request clarification or add additional context in comments.

1 Comment

without isolating the scope would be better

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.