angular js 变量不起作用

angular js variable not work

index.html

<div class="test" ng-controller="Ctrl">
    <button ng-click="removeTask(10);">remove</button>
<div>

app.js

app.controller('Ctrl', function($scope) {
    $scope.removeTask = function(taskId) {
        alert("Task Id is " + taskId);
    };
    var statement = "";
    db.transaction(function (tx) {
        //tx.executeSql('DROP TABLE IF EXISTS test_table');
        statement = "select * from objects where o.TYPES=' + taskId' GROUP BY objectid";

alert 消息完美运行,但是当我尝试在 select 语句中使用变量 taskId 时,它不起作用。

app.controller('Ctrl', function($scope) {
    $scope.removeTask = function(taskId){
    alert("Task Id is "+taskId);
    $scope.taskId = taskId;
};


var statement = "";

 db.transaction(function (tx) {

    //tx.executeSql('DROP TABLE IF EXISTS test_table');

    statement = "select * from objects where o.TYPES='+$scope.taskId+' GROUP BY objectid";

请注意,您必须将任务 ID 分配给范围变量以便稍后使用。

您需要在函数内部进行数据库事务。

app.controller('Ctrl', function($scope) {
    var statement = "";
    $scope.removeTask = function(taskId) {
        alert("Task Id is " + taskId);

        db.transaction(function (tx) {
        //tx.executeSql('DROP TABLE IF EXISTS test_table');
        statement = "select * from objects where o.TYPES='+taskId' GROUP BY objectid"; 
        };
    };

taskId 等函数参数仅在函数内部可用。