任何将vis.js与AngularJS一起使用的人
Anyone using vis.js with AngularJS?
我正在尝试将vis.js与AngularJS一起使用。它运行良好,我制定了一个简单的指令。。。但我需要使用这里列出的一些事件,但它们并没有被解雇。
在这个示例中,graph.on('select', ...)
事件侦听器没有被激发,我如何做到这一点有什么问题吗?
以下是我正在做的:
app.directive('visGraph', [function() {
return {
restrict: 'AE',
scope: {
data: '=data',
options: '=options'
},
link: function(scope, element, attrs) {
var container = element[0];
var graph = null;
graph = new vis.Graph(container, scope.data, scope.options);
scope.$watch(function() {
return scope.data;
}, function(value) {
graph = new vis.Graph(container, scope.data, scope.options);
});
graph.on('select', function (properties) {
console.info('select.properties.nodes', properties.nodes);
console.info('select.properties.edges', properties.edges);
});
}
};
}]);
有人能帮忙吗?
我刚刚解决了这个问题。在我的示例中,双击节点会重定向到节点详细信息。我只是把数据和选项转移到我的控制器上。这段代码是从Coffeescript编译的,所以它不是最完美的JS:
angular.module("myApp.directives").directive("visGraph", function($timeout, $window) {
return {
restrict: "AE",
link: function(scope, element, attrs) {
var buildGraph;
buildGraph = function(scope, element) {
var container, graph;
container = element[0];
graph = null;
graph = new vis.Graph(container, scope.data, scope.options);
return graph.on('doubleClick', function(properties) {
if (properties.nodes.length !== 0) {
return $window.location = FRONTEND_URL + properties.nodes;
}
});
};
// Wait for data asynchronously with $resource in the controller
scope.$watch('data', function(newval, oldval) {
buildGraph(scope, element);
}, true);
}
};
});
在控制器中,定义$scope.data
和$scope.options
。然后,您可以在标记中添加vis-graph
。
希望它能有所帮助!
我在这方面做了一些工作(简单)。。。所以,我刚刚把你的代码和我的代码混合在一起。。。我在不需要将数据重定向到控制器的情况下就可以实现这一点。
基本上,我添加了告诉指令我想在vis图上触发哪个事件的可能性,以及从指令内部调用控制器函数的回调函数:
<div id="graph" vis-graph data="graph.data" options="graph.options" event="select" callback="callbackFunction(params)"></div>
我用我的指令和一个简单的用法示例在GitHub上创建了一个repo。
请随意查看!
相关文章:
- 如何将eventListeners与Angularjs+Electron一起使用
- D3.js气泡图;t与AngularJS一起出现
- 如何使用AngularJS将if语句conditon与json响应一起使用
- 为什么Angularjs验证don't与输入[type=“number”]一起工作
- 为什么 HTML 中的 Value 属性在与 AngularJS 中的 ng-model 一起使用时不起作用
- 获得错误“;对象没有方法'jScrollPane'"与AngularJS一起使用时
- 将html ID与angularJS一起使用
- AngularJS和JS Math.max.apply()不能一起工作
- 400错误请求仅使用AngularJs,与jQuery一起使用
- 如何在 AngularJS 中与其他参数一起上传 http.post 的图像文件
- 如何将 Bootstrap Timepicker 与 AngularJS 一起使用
- 无法让 animationjs 与 AngularJS 一起工作
- 如何在 AngularJS 中将自定义指令与外部 HTML 模板捆绑在一起
- Jquery append() 不与 angularjs 一起使用
- 一段时间后隐藏与 angularjs 表单验证一起显示的错误标签
- javascript [],[[]] 和 [{}] 在 angularJS 中与 ng-repeat 一起使用时的工作差
- 将Jquery UI与AngularJS一起使用的优点和缺点是什么?
- AngularJS - 将then()与$http服务一起使用
- 将 Json 文件存储在 AngularJS 变量中,以便与“ng-repeat”一起使用
- 将ng个模型加在一起angularjs