AngularJS自定义指令ng repeat,无法调用null的方法'insertBefore'
在我的习惯中,我有map指令和marker指令,marker指令需要map指令 以下是我的问题的简化版本,我不能使用ng repeatAngularJS自定义指令ng repeat,无法调用null的方法'insertBefore',angularjs,ng-repeat,angularjs-google-maps,Angularjs,Ng Repeat,Angularjs Google Maps,在我的习惯中,我有map指令和marker指令,marker指令需要map指令 以下是我的问题的简化版本,我不能使用ng repeat <!DOCTYPE html> <html ng-app="testapp"> <head> <script src="http://code.angularjs.org/1.2.5/angular.js"></script> <script> var testapp = angular.m
<!DOCTYPE html>
<html ng-app="testapp">
<head>
<script src="http://code.angularjs.org/1.2.5/angular.js"></script>
<script>
var testapp = angular.module('testapp', []);
testapp.directive('map', [
function () {
return {
restrict: 'E',
controller: function($scope) {
},
link: function (scope, element, attrs) {
element.html("this will be a map");
}
};
}
]);
testapp.directive('marker', [
function () {
return {
require: '^map',
restrict: 'E',
link: function (scope, element, attrs, mapController) {
console.log('position', attrs.position);
}
};
}
]);
function MyCtrl($scope) {
$scope.positions = [[39, -90],[38, -91]];
}
</script>
</head>
<body ng-controller="MyCtrl">
<map zoom="12" center="[39, -90]">
<marker ng-repeat='p in positions' position="{{ p }}"></marker>
</map>
</body>
</html>
仅此一项就很有效。
我认为当父指令被操纵时,问题就出现了。
然而,由于我们使用的是指令,它必须操作dom
如果有任何帮助,我们将不胜感激。问题是您正在使用替换地图标记的内容
element.html("this will be a map");
相反,如果您尝试附加,它将毫无问题地工作
element.append("this will be a map");
问题是您正在用替换地图标记的内容
element.html("this will be a map");
相反,如果您尝试附加,它将毫无问题地工作
element.append("this will be a map");
谢谢,就这么简单。谢谢,就这么简单。