简体   繁体   English

未调用函数且未打印console.log

[英]Function not being called and console.log not printing

My Angular function is not getting called and it should be the simplest thing. 我的Angular函数没有被调用,应该是最简单的事情。

Inside the function, I have a console.log() statement that does not print. 在函数内部,我有一个console.log()语句不打印。

I have duplicated this code before (minus the jQuery) so maybe that is the issue?? 我之前已经复制了此代码(减去了jQuery),所以也许是问题所在??

Here is the .js file: 这是.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

Here is the condensed HTML: 这是压缩的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>
               ....

So when I click the button XG I want it to hide certain divs. 因此,当我单击按钮XG时,我希望它隐藏某些div。

That was not working so I put a log statement in and even that did not show up. 那是行不通的,所以我输入了一条日志语句,甚至没有显示出来。

What am I doing wrong? 我究竟做错了什么?

<section id="features" class="features" ng- controller="ContentController">

You have a space between ng- and controller . ng-controller之间有一个空格。 The following should work: 以下应该工作:

<section id="features" class="features" ng-controller="ContentController">

Remove all your code and you can see the problem: 删除所有代码,您将看到问题:

(function($) {

})();

})(jQuery); // End of use strict

should be 应该

(function($) {

})(jQuery);// End of use strict

Also, it isn't necessary to wrap angular inside of a closure. 另外,也不必将角形包装在闭合内。

I'm not familiar with Angular at all, but according to what I saw here, you may be lacking a ng-app="myContent" attribute in one of your tags: 我对Angular一点都不熟悉,但是根据我在这里看到的内容,您可能在其中一个标签中缺少ng-app="myContent"属性:

W3 school angular W3学校角

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM