Javascript 未调用函数且未打印console.log
我的角函数没有被调用,它应该是最简单的东西 在函数内部,我有一个不打印的Javascript 未调用函数且未打印console.log,javascript,jquery,angularjs,logging,Javascript,Jquery,Angularjs,Logging,我的角函数没有被调用,它应该是最简单的东西 在函数内部,我有一个不打印的console.log()语句 我以前复制过这段代码(减去jQuery),所以这可能就是问题所在 以下是.js文件: (function($) { "use strict"; // Start of use strict // jQuery for page scrolling feature - requires jQuery Easing plugin $(document).on('click', 'a.page-s
console.log()
语句
我以前复制过这段代码(减去jQuery),所以这可能就是问题所在
以下是.js文件:
(function($) {
"use strict"; // Start of use strict
// jQuery for page scrolling feature - requires jQuery Easing plugin
$(document).on('click', 'a.page-scroll', function(event) {
var $anchor = $(this);
$('html, body').stop().animate({
scrollTop: ($($anchor.attr('href')).offset().top - 50)
}, 1250, 'easeInOutExpo');
event.preventDefault();
});
// Highlight the top nav as scrolling occurs
$('body').scrollspy({
target: '.navbar-fixed-top',
offset: 100
});
// Closes the Responsive Menu on Menu Item Click
$('.navbar-collapse ul li a').click(function() {
$('.navbar-toggle:visible').click();
});
// Offset for Main Navigation
$('#mainNav').affix({
offset: {
top: 50
}
})
var app = angular.module('myContent',[]);
app.controller('ContentController',function($scope) {
$scope.XG = function(){
$scope.hideCCAD = true;
$scope.hideMATE = true;
$scope.hideWGA = true;
$scope.hideXG = true;
console.log("hello")
};
});
})();
})(jQuery); // End of use strict
以下是压缩的HTML:
<section id="features" class="features" ng-
controller="ContentController">
<div class="container">
<div class="row">
<div class="container-fluid">
<div class="containerX">
<div class="column column-one">
<ul>
<button ng-click="CCAD()"
type="button">CCAD</button>
<button ng-click="XG()"
type="button">XG</button>
<button ng-click="MATE()"
type="button">MATE</button>
<button ng-click="WGA()"
type="button">WGA</button>
</ul>
</div>
....
CCAD
XG
朋友
WGA
....
因此,当我单击按钮XG时,我希望它隐藏某些div
这是不工作,所以我把一个日志语句,甚至没有出现
我做错了什么?我对Angular一点也不熟悉,但根据我在这里看到的,您的一个标记中可能缺少
ng app=“myContent”
属性:
在ng-
和controller
之间有一个空格。以下方面应起作用:
删除所有代码,您可以看到问题:
(function($) {
})();
})(jQuery); // End of use strict
应该是
(function($) {
})(jQuery);// End of use strict
此外,没有必要在闭包内部包裹棱角 你有错误吗?让我们澄清一下。问题与
console.log()
无关,问题是没有调用您的函数。您是否在显示的HTML上方的某个位置有ng app指令?@sheplu否,我不相信我有error@ScottMarcus哦,好的!我想我的函数被调用了。我以为点击按钮就会调用它?这是由于stackoverflow上的格式,在我的HTML代码中没有空格