<p class="component-list">
<ul class="nav nav-tabs" id="PlugTabs" role="tablist">
<li role="presentation" ng-repeat="component_type in component_list"
ng-class="{active:$first}">
<a href="#{{component_type.id}}" role="tab" data-toggle="tab"
aria-controls="{{component_type.id}}" aria-expanded="true"
ng-bind="component_type.name"></a>
</li>
</ul>
<p class="tab-content" id="PlugContent">
<p role="tabpanel" class="tab-pane fade active in"
ng-repeat="component_type in component_list"
ng-class="{active:$first,in:$first}"
id="{{component_type.id}}">
<ul class="list-group">
<li class="list-group-item" ng-repeat="component_group in component_type.list">
<a href="#" class="list-group-header" ng-bind="component_group.name"></a>
<p class="boxes">
<p se-component></p>
</p>
</li>
</ul>
</p>
</p>
</p>
<p class="box" ng-repeat="component in component_group.list"
controller="{{component.controller}}" draggable="true">
<img src="{{component.image}}">
<label ng-bind="component.name"></label>
</p>
// se-component-list
Base.directive('seComponentList', function() {
return {
restrict: 'E',
replace: true,
templateUrl: STATIC_PATH + 'js/seditor/tpls/base.component_list.tpl',
controller: ['$scope', 'InitBaseData', function($scope, InitBaseData) {
InitBaseData.getComponentList().success(function(data) {
if (data && data.code == 0) {
$scope.component_list = data.component_list;
} else {
alert('网络异常,请稍后重试');
}
}).error(function(err) {
alert('网络异常,请稍后重试');
});
}]
};
});
// se-component
Base.directive('seComponent', function() {
return {
restrict: 'A',
replace: true,
templateUrl: STATIC_PATH + 'js/seditor/tpls/base.component.tpl',
link: function(scope, element, attr) {
element.bind('drop', function(event) {
event.preventDefault();
console.log('drop');
});
}
}
});
问题描述,如果把component.tpl的内容直接替换<se-component></se-component>,输出是正常的,但是我需要为component添加拖拽事件。目前的问题是,本来应该显示在其他boxes里面的内容都集中显示在最后一个boxes里面了,小弟刚学angular没多久,问题可能比较肤浅,但却是搜不到答案,还请讲解下,谢谢。
ng-repeat는 자체 범위를 생성하며 하위 범위는 컨트롤러의 $scope
해야 합니다.에 액세스하려면
$parent.xxx
seComponent는 속성을 설정하여 콘텐츠를 검색하는 것이 좋습니다
으아악se-comComponent의 replacement:true를 제거하면 디스플레이는 정상이 되지만, <se-comComponent>라는 라벨이 추가로 생겨서 보기에 좋지 않습니다