在Ionic框架中点击按钮出错



我正在尝试学习Ionic Framework。

对于了解这个框架的人来说,这可能是一个非常简单的问题。但是我做不到。

我需要做的就是在按钮点击时显示警报。

我的index.html代码包含button as:

<div class="bar bar-footer">
    <div class="title">
        <button class="button button-light" ng-click="showAlert()">
        Origin
        </button>
    </div>
</div>
这是我的js代码:
angular.module('todo', ['ionic'])
.controller('TodoCtrl', function($scope) {
    {
        // Use our scope for the scope of the modal to keep it simple
        scope: $scope
    }
});
$scope.showAlert = function() {
    alert("show");
};

我得到这个错误按钮点击:

Uncaught ReferenceError: $scope is not defined app.js:9
(anonymous function)

你知道我做错了什么吗?

请修改代码

angular.module('todo', ['ionic'])
.controller('TodoCtrl', function($scope) {
    {
        // Use our scope for the scope of the modal to keep it simple
        scope: $scope
    }
});
$scope.showAlert = function() {
    alert("show");
};

angular.module('todo', ['ionic'])
.controller('TodoCtrl', function($scope) {
    {
        // Use our scope for the scope of the modal to keep it simple
            $scope.showAlert = function() {
                  alert("show");
             };
    }
});

最新更新