簡體   English   中英

AngularJS按鈕ng單擊不起作用

[英]Angularjs button ng click not working

我有一個單擊打開彈出窗口的按鈕,調用addRow函數添加一行。 該行有一個單擊按鈕,可以添加新行。 但是,當我單擊此按鈕時,沒有函數被調用,並且沒有任何反應。 請幫忙。

<body ng-app="myApp" ng-controller="myCtrl">
    <div id="sample"><!-- onload="init()">-->
      <h3>Make your own Flowchart</h3>

        <button ng-click = "addSystem()" type="submit" id="btn-save">Add System</button>

在我的控制器內,代碼開始如下。

<script type="text/javascript">
    var app=angular.module('myApp',[]);
    app.controller('myCtrl', function($scope)
{
    $scope.sysInfo=[];

后來我有addSystem函數如下:

$scope.addSystem=function()
{
    console.log("Inside add system");
    var str="<form><table id=\"sysTab\"></table></form>";
    console.log("str is "+str);     
    $(str).dialog({
                                    modal: true,
                                    title:"Add system info",
                                    height:"auto",
                                    width:"auto",
                                    buttons: {
                                        'OK': function () {
                                            //console.log($('#sysName'));
                                            init();
                                            $( this ).dialog( "close" );
                                        },
                                            'Cancel': function () {
                                            $(this).dialog('close');
                                        }
                                    }
                                });
    $scope.addRow();
}
$scope.addRow=function()
{       
    $scope.index=$scope.index+1;
    console.log("index is "+$scope.index);
    console.log("Inside add row");
    $('#sysTab').append("<tr><td>System Name : </td><td><input rowid=\""+$scope.index+"\"type=\"text\" id=\"sysName"+$scope.index+"\"/></td><td><input type=\"text\" class=\"basic"+$scope.index+"\"/></td><td><input type=\"button\" value=\"+\" ng-click=\"addRow("+$scope.index+")\" title=\"Add new system info\"/></td><td><input type=\"button\" value=\"-\" onclick=\"deleteRow(this)\" title=\"Delete system info\"/><p id=\""+$scope.index+"\" style=\"display:none;\"></p></td></tr>");
    console.log("row added");

    $(".basic"+$scope.index).spectrum({
        color: "#f00",
        change: function(color) {
            console.log("Inside change");
            console.log($('#sysName'+$(this).closest('tr').index()).val());
            sysInfo.push({"index":$(this).closest('tr').index(), "name": $('#sysName'+$(this).closest('tr').index()).val(), "color":color.toHexString()});
            console.log(sysInfo);
        }
    });     
}

我嘗試調用$ scope.addRow(),但是沒有任何反應。 我嘗試了很多但沒有成功。 任何指針將大有幫助。

未定義$ scope的問題通過將范圍顯式調用為angular.element(document.getElementByID('master div element here')。scope()來解決

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM