Javascript 添加ng click to传单弹出onEachFeature功能
我已经创建了地图,并将其与我的geojson api连接起来。基本上,我希望用ng click链接每个标记弹出窗口。 像这样放置简单的html不会起作用,因为我必须编译它:Javascript 添加ng click to传单弹出onEachFeature功能,javascript,angularjs,leaflet,angular-leaflet-directive,Javascript,Angularjs,Leaflet,Angular Leaflet Directive,我已经创建了地图,并将其与我的geojson api连接起来。基本上,我希望用ng click链接每个标记弹出窗口。 像这样放置简单的html不会起作用,因为我必须编译它: layer.bindPopup("<button ng-click='()'>+feature.properties.title+</button>"); layer.bindpoop(“+feature.properties.title+”); 这就是我想做的。下面是这段代码。我得到“Error
layer.bindPopup("<button ng-click='()'>+feature.properties.title+</button>");
layer.bindpoop(“+feature.properties.title+”);
这就是我想做的。下面是这段代码。我得到“Error:[ng:areq]参数'scope'是必需的
"
$http.get(“http://markers.json)成功(功能(数据、状态){
角度。扩大范围{
geojson:{
数据:数据,
onEachFeature:功能(功能、层、范围){
var template=“”+feature.properties.title+”;
var linkFn=$compile(模板);
var内容=linkFn(范围);
层绑定弹出窗口(内容);
},
}
});
});
我对angular和js非常陌生,所以我想我在这里遗漏了一些明显和愚蠢的东西。谢谢 您不需要将
范围
作为参数添加到onEachFeature
方法中。变量$scope
中已存在范围:
$http.get("http://markers.json").success(function(data, status) {
angular.extend($scope, {
geojson: {
data: data,
onEachFeature: function(feature, layer) {
var template = "<button class='button button-clear button-small button-royal' ng-click='aa()'>" +feature.properties.title +"</button>";
var linkFn = $compile(template);
var content = linkFn($scope);
layer.bindPopup(content[0]);
}
}
});
});
$http.get(“http://markers.json)成功(功能(数据、状态){
角度。扩大范围{
geojson:{
数据:数据,
onEachFeature:功能(功能,图层){
var template=“”+feature.properties.title+”;
var linkFn=$compile(模板);
var内容=链接fn($scope);
layer.bindPopup(内容[0]);
}
}
});
});
示例:您不需要将
范围
作为参数添加到onEachFeature
方法中。变量$scope
中已存在范围:
$http.get("http://markers.json").success(function(data, status) {
angular.extend($scope, {
geojson: {
data: data,
onEachFeature: function(feature, layer) {
var template = "<button class='button button-clear button-small button-royal' ng-click='aa()'>" +feature.properties.title +"</button>";
var linkFn = $compile(template);
var content = linkFn($scope);
layer.bindPopup(content[0]);
}
}
});
});
$http.get(“http://markers.json)成功(功能(数据、状态){
角度。扩大范围{
geojson:{
数据:数据,
onEachFeature:功能(功能,图层){
var template=“”+feature.properties.title+”;
var linkFn=$compile(模板);
var内容=链接fn($scope);
layer.bindPopup(内容[0]);
}
}
});
});
示例:我有点怀疑,但它说:ReferenceError:scope不是definedit的
$scope
不是scope
,至少,看起来您是这样定义的,因为您使用的是angular.extend($scope,{……})代码>谢谢,有点停顿了。仍在努力把握这两者之间的区别。我确实像你说的那样。现在,当我点击marker时,它显示UncaughtTypeError:Failed to execute'appendChild'on'Node':参数1不是'Node'类型对不起,$compile
的返回类型是Array
,所以您需要使用第一项作为内容:。bindPopup(内容[0])
在我的答案中添加了一个工作示例。祝你的项目好运!我有点怀疑,但它说:ReferenceError:scope不是definedit的$scope
不是scope
,至少看起来像是这样定义的,因为您使用的是angular.extend($scope,{…})代码>谢谢,有点停顿了。仍在努力把握这两者之间的区别。我确实像你说的那样。现在,当我点击marker时,它显示UncaughtTypeError:Failed to execute'appendChild'on'Node':参数1不是'Node'类型对不起,$compile
的返回类型是Array
,所以您需要使用第一项作为内容:。bindPopup(内容[0])
在我的答案中添加了一个工作示例。祝你的项目好运!