如何从指令内部设置位置?
页面控制器:
$scope.position = 0;
页面中的图表指令:
<chart></chart>
在图表指令中,我对该头寸做了一些工作
angular.module('app')
.directive('chart',
function() {
return {
restrict: 'E',
scope: {
chartData: '=',
position: '='
},
link: function(scope, elem, attrs) {
var position = 10; // Need to set position so parent controller's position is updated
...
您忘记了将position
变量传递给指令。
<chart position="position"></chart>
然后在您的link
函数中,您可以使用scope
link: function(scope, elem, attrs) {
scope.position = your_value;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句