Javascript 使用ui sref创建动态链接插入highcharts
我正在尝试创建一个类别xAxis,作为应用程序其他区域的链接。我希望避免使用href,因为这将重新加载所有内容。我想问题的核心已经解决了Javascript 使用ui sref创建动态链接插入highcharts,javascript,angularjs,highcharts,Javascript,Angularjs,Highcharts,我正在尝试创建一个类别xAxis,作为应用程序其他区域的链接。我希望避免使用href,因为这将重新加载所有内容。我想问题的核心已经解决了 labels: { formatter: function () { let newvar = $compile(`<a class="link">${this.value} - ${vm.tableData.contentMain[this.pos].bothNeeded} - ${vm.tableData.content
labels: {
formatter: function () {
let newvar = $compile(`<a class="link">${this.value} - ${vm.tableData.contentMain[this.pos].bothNeeded} - ${vm.tableData.contentMain[this.pos].percentageCompleted}</a> - `)($scope)
return angular.element(newvar[0]);
},
useHTML: true
}
标签:{
格式化程序:函数(){
让newvar=$compile(`来自HighCharts Docs格式化程序
返回字符串。因此您与它无关。$compile
生成的DOM元素已被重新编译为摘要循环。所以它不是不正确的
但是,您可以生成如下字符串:
formatter: function () {
return '<div style="width:70px" onclick="alert(\''+this.value+'\')">'+$scope.someValues[this.value]+'</div>';
},
格式化程序:函数(){
返回'+$scope.someValues[this.value]+'';
},
我想避免使用href
您可以根据this.vaue
作为旁注:
当您在DOM$compile
d对象中打印时,会得到如下结果:{“0”:{“ng-1505336047666”:6},“length”:1}
其中0
是$scope
和1505336047666
元素id的id,这些元素id会重新生成每个构建好的,因此如果您提供一个cloneAttachFn,然后将结果分配给scope,您可以让它执行您所寻找的操作
HTML
你好,{{name}}!
{{newthing}}
Javascript
var myApp = angular.module('myApp',[]);
//myApp.directive('myDirective', function() {});
//myApp.factory('myService', function() {});
function MyCtrl($scope, $compile) {
$scope.name = 'Superhero';
$scope.link = $compile(`<div>Test</div>`)(
$scope,
function(clonedElement, scope) {
console.log(clonedElement[0]);
$scope.newthing = clonedElement[0].outerText;
}
);
}
var myApp=angular.module('myApp',[]);
//指令('myDirective',function(){});
//工厂('myService',function(){});
函数MyCtrl($scope$compile){
$scope.name='Superhero';
$scope.link=$compile(`Test`)(
$scope,
函数(clonedElement,作用域){
console.log(clonedElement[0]);
$scope.newthing=clonedElement[0].outerText;
}
);
}
问题是:你试过只返回newvar[0]吗?是的,我也试过一些更简单的方法,比如让newvar=$compile(test
)($scope)我仍然得到object似乎格式化程序只喜欢字符串,但我需要它来编译到hrefCan you post demo fiddle?当然,我可能缺少$compile周围的东西,因为我在做一个更简单的例子时遇到了类似的问题。有没有办法使用元素(el)不附加它?例如将其设置为$scope.el,然后使用{{el}?我尝试了类似的方法,但没有成功。由于highcharts需要格式化程序返回值,我认为这就是问题所在。@Organiccat我无法帮助您完成演示:尝试更新此示例:尝试避免使用更简单的示例。Appender因为我无法编译,这意味着ui sref将无法工作。上面的方法适用于更简单的字符串,但是ile是正确绑定ui sref所必需的。您必须返回字符串,以便获取状态并生成最终URL
var myApp = angular.module('myApp',[]);
//myApp.directive('myDirective', function() {});
//myApp.factory('myService', function() {});
function MyCtrl($scope, $compile) {
$scope.name = 'Superhero';
$scope.link = $compile(`<div>Test</div>`)(
$scope,
function(clonedElement, scope) {
console.log(clonedElement[0]);
$scope.newthing = clonedElement[0].outerText;
}
);
}