在treant.js图中创建ng-click按钮

时间:2015-11-06 20:07:48

标签: angularjs button graph tree click

我正在制作这样的仿冒赛事图(名字是随机创建的): Diagram

创建图形我通过angularJS文件中的java脚本为Treant创建输入:

/*
    Returns the HTML representing a match
*/
var populateGraphCell = function(match) {
    var content = "";
    if(match.registration_1 != undefined) {
        content += registration_to_html(match.registration_1);
    } else {
        content += "<button ng-click='bonjour()'>Add registration 1</button>";
    }
    content += "<br />";
    if(match.registration_2 != undefined) {
        content += registration_to_html(match.registration_2);
    } else {
        content += "<button>Add registration 2</button>";
    }
    content += "<br />";
    if(match.court != undefined) {
        content += court_to_html(match.court);
    } else {
        content += "<button>Add court</button>";
    }
    return content;
}
$scope.bonjour = function() {
    console.log("hello")
}

但我想知道是否有办法使用ng-click?,在谷歌浏览器调试模式下,我可以看到ng-click元素,但当我点击它时,没有任何反应

1 个答案:

答案 0 :(得分:0)

那是因为angular必须编译它。你可以使用这样的东西来编译它:

$timeout(function () {
    var element = $("your element id or class here");
    $compile(element)($scope)
});

以下是一位为您展示它的傻瓜:http://plnkr.co/edit/ctcpBpg8YOhlnxPXRBB1?p=preview

顺便说一下,这不是一个好习惯。你不应该操纵你的DOM对象。这是AngularJS存在的原因之一。您可以创建某种类型的指令。