我想为这个指令中的每个 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/