Angular.js NG-样式将不绑定值 [英] Angular.js ng-style won't bind value
问题描述
我有一个问题,angularjs甚至研究后,我只是找不到在哪里,我错了。
I've got a problem with angularjs and even after research I just couldn't find where I'm wrong.
我需要重新计算的CSS值左的一个元素。我使用了吴式指令,这将返回一个对象的CSS值的方法。那是 - 据我所知 - 我必须做的。但是,当我更新的价值,它不会更新的样式。
I need to recalculate the css value "left" for an element. I'm using the 'ng-style' directive and a method that will return an object with the css value. Thats - afaik - what I have to do. But when I update the value, it wont update the style.
的 NG-绑定用法:的
<div ng-style="getCssShiftObject()">
的方法来创建对象的
$scope.getCssShiftObject =function(){
return {'left':this.cssShift+'px'};
};
的方法来改变对象的
$scope.nextPosition = function(){
if((this.currentPosition+1) <= this.maxPosition){
this.currentPosition = this.currentPosition+1;
this.cssShift = (this.currentPosition*this.slideSize)*-1;
}
return this.currentPosition;
};
这将在内容另一个地方更新当我使用它像:
It will update at another place in the content when I use it like that:
{{getCssShiftObject()}}
我希望你能给麻省理工学院的一击,感谢您的时间!
I hope you can give mit a hit, thanks for your time!
推荐答案
THX您的时间!我解决了这个问题从Cherniv的投入,但我不知道怎么样。我改变了我创造价值的方式。现在,它的工作。
Thx for your time! I solved the Problem with the input from Cherniv, but I'm not sure how. I changed the way I create the values. Now it's working.
$scope.calcCssShift = function(){
this.cssShift = ($scope.currentPosition * $scope.slideSize)*-1;
};
$scope.getCssShiftObject =function(){
return {'left':$scope.cssShift+'px'};
};
$scope.nextPosition = function(){
if((this.currentPosition+1) <= this.maxPosition){
$scope.currentPosition = this.currentPosition+1;
$scope.calcCssShift();
}
};
这篇关于Angular.js NG-样式将不绑定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!