Angular 的新手,stackoverflow 的新手。几天来一直试图解决这个问题。这是我的问题:
我想将一组盒子居中。
有没有办法访问 div 的属性(带有 id 或类名)并在指令中操作它们?
在我的 html 中,我正在使用 ng-repeat 创建 div,这些 div 是显示的框。我有一个指令,我目前正在尝试使用它来查找和操作 html 中 div/指令的属性,但是我似乎无法做到这一点。
我用谷歌搜索了很多,发现了类似的问题,但在我的代码中似乎没有任何效果。
这是一个小提琴:http: //jsfiddle.net/3m87R/
app.directive('someBoxes', function()
{
return function(scope, element, attrs)
{
element.css('border', '1px solid white');
//element.css('width', '200px');
var body = angular.element(document).find('.bookitem');
console.log(body[0].offsetWidth);
if(scope.$last)
{
//console.log("element name is: " + element.attr("class"));
//console.log("element is: " + element);
//console.log($(".bookitem").children("div").attr("class"));
//console.log($('.container').children('div').attr('class'));
}
};
});
感谢您提供的任何帮助。