[英]angularjs how to pass element properties to ng-show function
There is one chart in my application like, 我的应用程序中有一张图表,例如,
<canvas id="line" class="chart chart-line" height="250" width="{{width_chart}}" chart-data="data" chart-labels="labels" chart-series="series" chart-options="options" chart-colors="colors" chart-dataset-override="datasetOverride" chart-click="onClick" ng-show="isChecked()"> </canvas>
And in isChecked function i want to get id of this canvas which is "line" in this case. 在isChecked函数中,我想获取此画布的ID,在这种情况下为“线”。 Then i want to check presence of this ID in one $scpoe.array , and based on presence i want to return true or false to make the chart show/hide.
然后,我想在一个$ scpoe.array中检查此ID的存在,并基于存在我想返回true或false来使图表显示/隐藏。
$scope.isChecked = function() {
console.log('i am in isChecked function');
console.log(this);
// some code
return true;
};
My problem is i am not able to get the ID in function by any mean. 我的问题是我无法以任何方式获取ID。 "this" is also not working.
“这个”也不起作用。 I tried the directive way mentioned in below, but that is also not working.
我尝试了下面提到的指令方式,但这也不起作用。
Pass element using ng-show AngularJS
使用ng-show AngularJS传递元素
Please help. 请帮忙。
ng-click="isChecked('line')"
In angularjs 在angularjs中
$scope.isChecked = function(id) {
console.log(id);
// some code
return true;
};
You can get the id like the following: 您可以获取如下所示的ID:
<div id="line" ng-click="ShowId($event)" ng-show="isChecked"></div>
$scope.ShowId = function(event){
var id = event.target.id;
if(id == 'line'){
$scope.isChecked = true;
}
};
Or: 要么:
<div id="line" ng-click="ShowId($event)" ng-show="isChecked('line')"
$scope.isChecked = function(id){
if(id == 'line'){
return true;
}else{
return false;
}
}
If you are getting that from another ng-repeat
or some other array just pass it as a model
. 如果您是从另一个
ng-repeat
或其他数组中获得的,只需将其作为model
传递即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.