Javascript 通过角度视图调用jQuery函数
有没有办法只在特定的Angularjs控制器/视图中调用jQuery函数? 例如,我只想在主视图中调用slides函数 幻灯片:Javascript 通过角度视图调用jQuery函数,javascript,jquery,angularjs,Javascript,Jquery,Angularjs,有没有办法只在特定的Angularjs控制器/视图中调用jQuery函数? 例如,我只想在主视图中调用slides函数 幻灯片: $('.slides').superslides(); app.js: var myApp = angular.module('myApp', ['ngRoute']); myApp.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
$('.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();
}
});
创建一个指令
JS:
myApp.directive( "superslides",
function()
{
return {
restrict: "A",
scope: {},
link: function ( scope, element, attrs )
{
$( element ).superslides();
}
}
}
)
html:
<ul superslides>
</ul>
不隔离范围会更好