我有一个问题,为每个面板在一个角手风琴儿童范围。
手风琴是使用这种格式的数据建立的:
$scope.accordionData = [
{'partial': 'desktop-ui/partials/test1.html', 'args':{'key1': $scope.args.users,'key2': 'http://www.sungard.com'}},
{'partial': 'desktop-ui/partials/test2.html', 'args':{'key1': $scope.args.contacts,'key2': 'http://financialsystems.sungard.com/solutions/asset-management'}}
];上面的数组中的两个对象包含
在“我的指令”中,我使用此代码为每个面板创建一个新的范围:
// element is the accordion and panels is a jQuery list of panels for the accordion and dataList is the data
function populatePanelsWithExtraArgs(element, dataList, panels) {
angular.forEach(dataList, function(data, index) { // for each panel
var dataArgs = data.args; // get the extra args
var panel = panels[index]; // get each panel from the jQuery list
panel = angular.element(panel); // convert to angular element
var childScope = panel.scope(); // create a new scope HERE IS THE PROBLEM
childScope.args = dataArgs; // add the args to each panel's scope.
});
}行'panel.scope();‘实际上没有创建一个新的作用域。作用域的id与主作用域的id相同。另外,第一个arg被第二个arg覆盖。
如果我试试这个:
panel.scope().$new()这是可行的,但随后它将“args”添加到名为$$childTail的内容(我使用的是铬调试器):
scope.$$childTail.args这意味着{{args.key1}不再工作了,因为变量args不再在主作用域中,而是在这个$$childTail上。
发布于 2014-05-25 10:26:44
为手风琴中的每个面板创建新作用域的doThe解决方案是用自己的指令编译面板DOM元素,从而自动创建唯一的作用域。
https://stackoverflow.com/questions/23760523
复制相似问题