鉴于具有相同ng-style
属性的3个元素,有没有办法控制ng-style
实际影响哪个元素?场景如下:用户可以与屏幕上的元素进行交互。在选择元素(通过单击它)后,用户可以使用input
连接到ng-style
ng-model
来控制其宽度x,y位置。每个元素都有一个不同的ID,传递给ngclick
函数(1,2或3)
$scope.selectClickedElm = function(elm){
console.log(elm);
clickedElement = elm;
//enable ng-style for element with the selected ID (1\2\3)
}
function createAndAppend(element){
var element;
if(creationObject[element]==true){
}else{
if(element =="input"){
element = angular.element("<"+element+" id='inputTag' ng-click='selectClickedElm(1)' ng-style='{width: w + \"px\",top: t + \"px\",left: l + \"px\"}' placeholder='input'>");
angular.element(document.getElementById('board')).append($compile(element)($scope));
}else if(element =="label"){
element= angular.element("<"+element+" id='labelTag' ng-click='selectClickedElm(2)' ng-style='{width: w + \"px\",top: t + \"px\",left: l + \"px\"}'>{{txt || 'Label'}}</"+element+">");
angular.element(document.getElementById('board')).append($compile(element)($scope));
}else{
element= angular.element("<"+element+" id='buttonTag' ng-click='selectClickedElm(3)' ng-style='{width: w + \"px\",top: t + \"px\",left: l + \"px\"}'>{{txt || 'Button'}}</"+element+">");
angular.element(document.getElementById('board')).append($compile(element)($scope));
}
}
}