[英]Function not being called and console.log not printing
我的Angular函數沒有被調用,應該是最簡單的事情。
在函數內部,我有一個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>
....
因此,當我單擊按鈕XG時,我希望它隱藏某些div。
那是行不通的,所以我輸入了一條日志語句,甚至沒有顯示出來。
我究竟做錯了什么?
<section id="features" class="features" ng- controller="ContentController">
ng-
和controller
之間有一個空格。 以下應該工作:
<section id="features" class="features" ng-controller="ContentController">
刪除所有代碼,您將看到問題:
(function($) {
})();
})(jQuery); // End of use strict
應該
(function($) {
})(jQuery);// End of use strict
另外,也不必將角形包裝在閉合內。
我對Angular一點都不熟悉,但是根據我在這里看到的內容,您可能在其中一個標簽中缺少ng-app="myContent"
屬性:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.