简体   繁体   English

AngularJS按钮ng单击不起作用

[英]Angularjs button ng click not working

I have a button on clicking which a popup is opened, addRow function is called to add a row. 我有一个单击打开弹出窗口的按钮,调用addRow函数添加一行。 This row has a button on clicking which new rows can be added. 该行有一个单击按钮,可以添加新行。 However when i click on this, no function is called and nothing happens. 但是,当我单击此按钮时,没有函数被调用,并且没有任何反应。 Please help. 请帮忙。

<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>

Within my controller code starts as follows. 在我的控制器内,代码开始如下。

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

later i have addSystem function is as follows: 后来我有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);
        }
    });     
}

i tried calling as $scope.addRow() but i am getting no response. 我尝试调用$ scope.addRow(),但是没有任何反应。 i tried a lot without any success. 我尝试了很多但没有成功。 Any pointers will be greatly helpful. 任何指针将大有帮助。

未定义$ scope的问题通过将范围显式调用为angular.element(document.getElementByID('master div element here')。scope()来解决

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM