我正在使用 Angular Material Dialog 来根据我的数据内容生成弹出窗口。我正在使用 ng-repeat 创建按钮,在其单击时会生成对话框。但我无法将单个对象作为范围注入控制器。这是Plunker的链接
代码文件如下:
应用程序.js
var app = angular.module('myApp', ['ngMaterial']);
app.controller('mainCtrl', function($scope,$mdDialog) {
$scope.siteData = [{
Name: 'Google',
URL: 'https://www.google.com'
}, {
Name: 'Yahoo',
URL: 'https://www.yahoo.com'
}, {
Name: 'Rediff',
URL: 'https://www.rediff.com'
}];
$scope.showDialog = function(ev,scopeObj) {
$mdDialog.show({
//template: 'myModal',
template: '<md-dialog>' +
' <md-dialog-content>' +
' {{URL}} ' +
' </md-dialog-content>' +
'</md-dialog>',
scope:scopeObj,
targetEvent: ev,
clickOutsideToClose :true,
preserveScope :true,
clickOutsideToClose:true,
});
};
});
索引.html
<html lang="en" ng-app="myApp">
<head>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=RobotoDraft:300,400,500,700,400italic">
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/angular-material/0.10.0/angular-material.css">
<meta name="viewport" content="initial-scale=1" />
</head>
<body ng-controller="mainCtrl">
<div ng-repeat="site in siteData">
<md-button class="md-raised md-primary" ng-click = "showDialog($event,site)">{{site.Name}}</md-button>
</div>
<!-- Angular Material Dependencies -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-animate.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-aria.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-material/0.10.0/angular-material.js"></script>
<script src="app.js"></script>
</body>
</html>
请提出任何更改以实现此目的。