$location在使用d3.js时不能正常工作的AngularJS
$location在使用d3.js时不能正常工作的AngularJS
这是我第一次遇到这个问题,不知道为什么。 我使用d3创建一个悬挂图表。 有一个单击事件正在触发并调用changePath()。 我看到控制台日志,这意味着我可以访问$location.path但是当我尝试设置它时,什么都不发生:没有新页面,也没有错误页面!
如果我不通过angular改变路径,我的路由器就无法维护作用域,这就是我要寻找的。有什么线索吗?
var parentCtrl = function($scope,$location){
$scope.makeBSC = function(){
var changePath = function(el){
console.log($location.path());
$location.path(el)
}
var width = 405,
height = 420,
color = d3.scale.category20c();
var vis = d3.select(\"#bscChart\").append(\"svg\")
.attr(\"width\", height)
.attr(\"height\", width);
var partition = d3.layout.partition()
.size([width, height])
.value(function(d) {return d.size; });
var json = data ;
vis.data([json]).selectAll(\"rect\")
.data(partition.nodes)
.enter().append(\"rect\")
.attr(\"y\", function(d) { return d.x; })
.attr(\"x\", function(d) { return d.y; })
.attr(\"height\", function(d) { return d.dx; })
.attr(\"width\", function(d) { return d.dy; })
.attr(\"class\",function(d){
if(d.isSel) return \"rectBlue\"
return \"rectGray\"
}).on(\"click\", function(d){
changePath(d.goTo);
});
}
}
\n\nOCD让我不能把这个问题“悬而未决”。正如groner指出的那样......嗨,我认为你会在这个问题中找到你的答案:AngularJS $location not changing the path\n\n另外,这里有一个小彩蛋。看看这些指令,它们包装了d3:http://www.fullscale.co/dangle/