2017-09-11 51 views
-1

函數GameController($ scope)不起作用,我不知道爲什麼,有人可以幫忙嗎?無法使用函數int控制器

(function() { 
    angular.module('MemoryGame').controller('GameController', GameController); 

    GameController.$inject = ['$scope']; 
    console.log("hhhhhhh"); 


    function GameController($scope) { 
    console.log("gggggg"); 

    var cards = document.querySelectorAll(".all-cards"); 
    var i = 0; 
    var textArray = []; // array that saving the text of the car 
    var count = 0; // count the card flipped 
    var save_cards = []; 



    cards.forEach((card) => { 
     card.addEventListener('click', function() { 


     }); 
    }); 
    } 
})(); 
+0

你可以請分享你得到的錯誤。這將有助於確定問題。 –

+0

發佈相關的HTML也很有用。 –

回答

0

不知道你得到了什麼錯誤 - 但嘗試設置你的控制器有點不同。您可以在聲明控制器的同時注入$ scope對象。

var app = angular.module('MemoryGame', []); 

app.controller('GameController', function($scope) { 

    var cards = document.querySelectorAll(".all-cards"); 
    var i = 0; 
    var textArray = []; // array that saving the text of the car 
    var count = 0; // count the card flipped 
    var save_cards = []; 

    cards.forEach((card) => { 
     card.addEventListener('click', function() { 
    }); 
}); 

此外,你是否在HTML中正確聲明瞭你的ng-app和ng-controller?

<body ng-app="MemoryGame"> 
    <div ng-controller="GameController"> 
     {{hello}} 
    </div> 
</body> 
+0

您應該分享任何錯誤消息和一些HTML –

相關問題