示例:
setting.html
这个html用于动态显示md-switch切换按钮
<md-dialog-content ng-repeat="notifications in languagelabels.notification">
<div layout="row">
<div flex=70>{{ ::notifications }}</div>
<div flex=30>
<md-switch ng-model="data.notification.subscription" aria-label="{{::notifications}}"></md-switch>
</div>
</div>
</md-dialog-content>
controller.js 这是从md-switch
获取值app.controller('SettingController', function($scope, $rootScope, $http, $mdDialog, data, $timeout) {
$scope.languagelabels = data;
//console.log(data.notification);
//$scope.notifications=['New Booking','Cancellation','Modification','Last Minute Booking'];
var old = {
subscription: (window.localStorage.getItem('subscrid') == 1) ? true : false
};
$scope.data={};
$scope.data.notification = {
subscription: (window.localStorage.getItem('subscrid') == 1) ? true : false
};
$scope.cancel = function() {
$mdDialog.hide(0);
} });
答案 0 :(得分:0)
您没有使用notification
data
对象
你应该初始化它
$scope.data={notification:{}};
或者尝试以下方式
$scope.data={notification:{subscription:(window.localStorage.getItem
('subscrid') == 1) ? true : false
}};