2017-02-27 13 views
0

ユーザーがボタンをクリックしたときにログメッセージを表示しようとしています。代わりに、このエラーが現れます:

angular.module('app.controllers', []) 
.controller('page4Ctrl', ['$scope', '$stateParams', function ($scope, $stateParams) { 
$scope.scanBarcode() = function() 
{ 
    console.log("hello"); 
}; 

}]) 

とここに私のhtmlコードだ:

TypeError: $scope.scanBarcode is not a function 
at new <anonymous> (controllers.js:8) 
at Object.instantiate (ionic.bundle.js:18015) 
at $controller (ionic.bundle.js:23417) 
at Object.self.appendViewElement (ionic.bundle.js:59908) 
at Object.render (ionic.bundle.js:57901) 
at Object.init (ionic.bundle.js:57821) 
at Object.self.render (ionic.bundle.js:59767) 
at Object.self.register (ionic.bundle.js:59725) 
at updateView (ionic.bundle.js:65400) 
at ionic.bundle.js:65377 
(anonymous) @ ionic.bundle.js:26799 

ここに私のcontroller.jsコードです

<ion-view title="Page1" id="page18"> 
<ion-content padding="true" class="has-header"> 
<button id="page4-button4" class="button button-positive button-block" ng-click="scanBarcode()">Scan</button> 
<button id="page4-button5" class="button button-positive button-block">Display Scanned Data</button> 

は何ができますか問題?

+0

:これを試してみてください、すなわちscanBarcode

関数名の後()を使用してはいけません。おもう。 '' –

+0

ありがとう、エラーがまだ表示されます.. –

答えて

1

私は間違った機能を定義したと思います。あなたは `イオンcontent`以内にあなたのコントローラを定義する必要があり

$scope.scanBarcode = function()//no() after the name 
{ 
    console.log("hello"); 
}; 
関連する問題