Uncaught SyntaxError:意外的字符串 - 在我的Angular函数的返回中

时间:2014-10-16 20:41:31

标签: javascript string angularjs return

不知道为什么我在这里收到此错误,我之前在其他应用中使用过这种确切类型的功能。这里唯一的区别是我将它包含在Angular Controller中,这可能与此错误有关吗?

enter image description here

// Controller for Add Customer
app.controller('AddCustomerController', function($scope) {

    $scope.deactivate_btn = false;

    // Check all users:
    this.checkAll = function() {
        var checkboxes = document.getElementsByName('checkboxCustomer');
        var checkAll = document.getElementsByName('checkboxAll');

        for (var i = 0, n = checkboxes.length; i < n; i++) {
            checkboxes[i].checked = checkAll[0].checked;
        }
    };

    function buildAddedSiteRow(id, name, address, loc1, loc2, city, state, zip) {
        id      = id      || " ";
        name    = name    || " ";
        address = address || " ";
        loc1    = loc1    || " ";
        loc2    = loc2    || " ";
        city    = city    || " ";
        state   = state   || " ";
        zip     = zip     || " ";

        var number = 1 + Math.floor(Math.random() * 6);

        return "<tr class='added_sites_tbody'><td><div class='check-label'><input ng-click='deactivate_btn = !deactivate_btn' ng-class='{ active: deactivate_btn }' type='checkbox' name='checkAddSite' id='"+id"' class='css-checkbox' /><label for='"+id"' class='css-label radGroup1 clr'>"+id"</label></div></td><td>"+name"</td><td>"+address"</td><td><div class='add_sites_location'><p>"+loc1"</p> <p>"+loc2"</p></div></td><td>"+city"</td><td>"+state"</td><td>"+zip"</td><td></td></tr>";
    };
});

1 个答案:

答案 0 :(得分:4)

return "<tr class='added_sites_tbody'><td><div class='check-label'><input ng-click='deactivate_btn = !deactivate_btn' ng-class='{ active: deactivate_btn }' type='checkbox' name='checkAddSite' id='"+id"' class='css-checkbox' /><label for='"+id"' class='css-label radGroup1 clr'>"+id"</label></div></td><td>"+name"</td><td>"+address"</td><td><div class='add_sites_location'><p>"+loc1"</p> <p>"+loc2"</p></div></td><td>"+city"</td><td>"+state"</td><td>"+zip"</td><td></td></tr>";
// The errors are here ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------^ and ------------------------------------^ and ---------------------------------^ and ------------------------^ and -------------^ and so on

您需要在每个位置+