我是棱角分明的新手。我想用angular js实现。
这是我的代码。
的index.html
<div class="container" ng-controller="headerController">
<span ng-repeat="b in button" >
<button button-control id='{{b}}' ng-click = '{{b}}()'>{{b}}</button>
</span>
</div>
app.js
.controller('headerController',function($scope,$location){
$scope.button = ['prev','toggle','reserve','next'];
})
.directive('buttonControl',function(){
return{
restrict: 'AE',
replace: true,
link:function(scope,elem,attrs){
var api = elem.spritespin('api');
scope.prev = function(){
api.stopAnimation(); //**problem**
}
scope.toggle = function(){
}
scope.reserve = function(){
}
scope.next = function(){
}
}
}
})
问题 当我执行api.stopAnimation()时,stopAnimation()使用此对象指向当前范围而不是elem。我可能错了。
任何帮助表示赞赏
由于
答案 0 :(得分:0)
我经历了Chrome AngularJS Batarang并且我必须做
scope.$parent.$parent.api = new Object
覆盖父范围
现在在buttonController指令中。我只需要执行
即可访问api对象 app.directive('buttonControl',function(){
return{
restrict: 'AE',
replace: true,
link:function(scope,elem,attrs){
console.log(scope.api);
}
})