D3 within an AngularJS app

后端 未结 4 767
予麋鹿
予麋鹿 2020-12-12 12:41

I\'m trying to create my first app with AngularJS. It looks neat, but there\'s a lot of abstraction, and I\'m just curious if anyone has advice on the most idiomatic way to

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-12 13:29

    If we use d3 inside a directive to generate elements with other Angular directives (as I think you will find is quite a common requirement) you can call $compile on the end of the UPDATE phase of the rendering process with the call() method. Like this (assuming we're rendering a bunch of circles):

    mySvg.selectAll("circle")
                    .data(scope.nodes)
                    .enter()
                    .append("circle")
                    .attr("someDirective")
                    .call(function(){
                        $compile(this[0].parentNode)(scope);
                    });
    

提交回复
热议问题