我试图用json数据创建对话框。
$scope.showAttributeData = function(data) {
$scope.feature = data
console.log($scope.feature)
var that = this;
var useFullScreen = ($mdMedia('sm') || $mdMedia('xs')) && that.customFullscreen;
$mdDialog.show({
locals: {
feature: $scope.feature
},
controller: attributeDialogController,
controllerAs: 'attributeDialog',
templateUrl: 'attribute-dialog.template.html',
parent: angular.element(document.body),
clickOutsideToClose: true,
hasBackdrop: false,
fullscreen: useFullScreen,
openFrom: angular.element(document.querySelector('#left')),
closeTo: angular.element(document.querySelector('#left'))
});
$scope.$watch(function() {
return $mdMedia('xs') || $mdMedia('sm');
}, function(wantsFullScreen) {
return that.customFullscreen = wantsFullScreen === true;
});
};
但是在tempalte数据中没有reder。看起来模板似乎没有从控制器中捕获数据。
<script type="text/ng-template" id="attribute-dialog.template.html">
<md-dialog id="attribute-dialog">
<md-toolbar>
<div class="md-toolbar-tools">
<h2>Attribut info</h2>
<span flex></span>
<md-button class="md-icon-button" ng-click="attributeDialog.close()">
<md-icon md-svg-src="img/icons/ic_close_24px.svg" aria-label="Close dialog"></md-icon>
</md-button>
</div>
</md-toolbar>
<md-dialog-content>
<div class="md-dialog-content">
<table>
<thead>
<tr>
<th>Attr</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="(key, value) in feature">
<td> {{key}} </td>
<td>
<input type="text" ng-model="feature[key]"/>
</td>
</tr>
</tbody>
</table>
</div>
</md-dialog-content>
<md-dialog-actions layout="row">
<span flex></span>
<md-button type="submit" ng-click="attributeDialog.close()" class="md-raised md-primary">ОК</md-button>
</md-dialog-actions>
</md-dialog>
</script>
那么,它可以是什么? 此外,对话框模板相当新,作为控制器。将来,我将使用ng-model添加可编辑信息。并且,可能有人知道,它是如何正确克里特的? 我从传单地图传递信息
mainLayer.eachLayer(function(layer) {
layer.on({
click: function() {
var scope = angular.element($("#main")).scope().showAttributeData(layer.feature.properties);
},
});
});
另外,我开始学习角度一周前,如果你发现一些错误或错误编写代码,请写下来))
答案 0 :(得分:1)
我已经创建了一个测试示例来帮助您使用标记 - CodePen
标记
<div ng-controller="MyController as vm" ng-cloak="" ng-app="app">
<md-button class="md-primary md-raised" ng-click="vm.open($event)">
Custom Dialog
</md-button>
<script type="text/ng-template" id="test.html">
<md-dialog id="attribute-dialog">
<md-toolbar>
<div class="md-toolbar-tools">
<h2>Attribut info</h2>
<span flex></span>
<md-button class="md-icon-button" ng-click="attributeDialog.close()">
<md-icon md-svg-src="img/icons/ic_close_24px.svg" aria-label="Close dialog"></md-icon>
</md-button>
</div>
</md-toolbar>
<md-dialog-content>
<div class="md-dialog-content">
<table>
<thead>
<tr>
<th>Attr</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="(key, value) in feature">
<td> {{key}} </td>
<td>
<input type="text" ng-model="feature[key]"/>
</td>
</tr>
</tbody>
</table>
</div>
</md-dialog-content>
<md-dialog-actions layout="row">
<span flex></span>
<md-button type="submit" ng-click="attributeDialog.close()" class="md-raised md-primary">ОК</md-button>
</md-dialog-actions>
</md-dialog>
</script>
</div>
JS
angular.module('app',['ngMaterial'])
.controller('MyController', function($scope, $mdDialog) {
this.open = function(ev) {
$scope.feature = {
blah: "blah",
yah: "yah"
}
$mdDialog.show(
{
templateUrl: "test.html",
clickOutsideToClose: true,
scope: $scope,
preserveScope: true,
controller: function($scope) {
},
});
};
})
答案 1 :(得分:0)
尝试放置目标事件:
$scope.showAttributeData = function(data,ev) {
$scope.feature = data
console.log($scope.feature)
var that = this;
var useFullScreen = ($mdMedia('sm') || $mdMedia('xs')) && that.customFullscreen;
$mdDialog.show({
locals: {
feature: $scope.feature
},
controller: attributeDialogController,
controllerAs: 'attributeDialog',
templateUrl: 'attribute-dialog.template.html',
targetEvent: ev,
parent: angular.element(document.body),
clickOutsideToClose: true,
hasBackdrop: false,
fullscreen: useFullScreen,
openFrom: angular.element(document.querySelector('#left')),
closeTo: angular.element(document.querySelector('#left'))
})
.then(function(credentials) {
return that.showToast("Добро пожаловать, " + credentials.username + ".");
});
$scope.$watch(function() {
return $mdMedia('xs') || $mdMedia('sm');
}, function(wantsFullScreen) {
return that.customFullscreen = wantsFullScreen === true;
});
};