【发布时间】:2013-08-09 05:13:15
【问题描述】:
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'));
}
};
});
感谢您提供的任何帮助。
【问题讨论】:
-
你看过 transclude 吗?我认为在自定义标签中使用 ng-repeat 会更好
标签: javascript html angularjs