2016-07-28 44 views
0

對於Angular來說,我真的很陌生,我一直無法找到解決方案,因爲我使用控制器獲得「Bad Argument」錯誤。試圖使用。 我不確定它是否完全是其他東西,或者我如何定義控制器本身。AngularJS錯誤:獲取ng:areq在聲明我的控制器時出現錯誤的參數

在此先感謝您的任何反饋意見!

的JS

app.controller('questionCtrl', ['$http', '$scope', function($http, $scope) { 

      console.log('question posting is ready'); 
      var questionText = $('input[id="qASectionHead"]').val(); 
      var businessIdNo = localStorage.getItem('vm.id'); 
      console.log(businessIdNo); 

      $scope.askButton = function() { 

       console.log('ask has been clicked') 

       console.log('The user has typed: ' + questionText); 

       $http({ 
        url: 'url', 
        method: 'POST', 
        data: { 
         question_text: questionText, 
         business_id: businessIdNo, 
        }, 
        headers: { 
         'Authorization': 'token' 
        }, 
       }).success(function(data) { 

        console.log(data); 
        }); 
        }; 
       }]); 

的HTML

   <div id="qASectionContain" ng-controller="questionCtrl"> 
      <input id="qASectionHead" placeholder="ask this business a question"> 
       <button ng-click="askButton()"> 
       ask 
       </button> 
+0

一切似乎都很好,你提供了一個小提琴或plunkr –

+1

我沒有看到任何內在的錯誤,你提供了什麼,這意味着錯誤必須在別的地方。也許你可以展示更多(全部)你的控制器代碼? – Lex

+0

感謝您的建議。我繼續在帖子中添加我的控制器代碼的其餘部分。 – ksaund

回答

0

謎已經解決了! 它有助於如果js文件正確鏈接在您的索引中..... oops

感謝那些評論!