gpt4 book ai didi

angularjs - 如何为指令的每个实例添加唯一的 id?

转载 作者:行者123 更新时间:2023-12-03 14:29:46 24 4
gpt4 key购买 nike

我想为这个指令中的每个 div 添加一个唯一的 ID,以便我可以指定谷歌地图应该传递的元素:

directive('gMap', function(googleMaps){
return{
restrict: 'E',
replace: true,
transclude: true,
template: "<div id="{{unique_ID}}"></div><div ng-transclude></div>",
scope: true,
link: function(scope, element, attrs){


//create the map
var center = googleMaps.makePosition(attrs.centerlat, attrs.centerlong)
//update map on load
var options = googleMaps.setMapOptions(center, attrs.zoom);
scope.map = googleMaps.createMap(options, unique_id)
},
};
}).

最佳答案

不引入大量额外代码的简单解决方案是使用 Date.now()
例如会生成:1397123701418

关于angularjs - 如何为指令的每个实例添加唯一的 id?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22983911/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com