我有一個指令和一個控制器。該指令的休耕:Angular指令和控制器
calcP.directive('modalDialog', function() {
return {
restrict: 'E',
scope: {
show: '='
},
replace: true,
transclude: true,
link: function(scope, element, attrs) {
scope.dialogStyle = {};
if (attrs.width)
scope.dialogStyle.width = attrs.width;
if (attrs.height)
scope.dialogStyle.height = attrs.height;
**scope.hideModal = function() {
scope.show = false;
delete $sope.types.individual;**
};
},
template: "..."
};
});
我的控制器:
calcP.controller('calcPCtrl', function($scope, $http, $window, emailSenderEndpoint) {
$scope.getVariantDomovoy = function() {
$scope.types.domovoy = $scope.variants.domovoy;
};
$scope.getVariantIndividual = function() {
$scope.types.individual = $scope.variants.individual;
};
...
$scope.modalShown = false;
$scope.toggleModal = function() {
$scope.modalShown = !$scope.modalShown;
};
});
我的模板:
template: "<div class='ng-modal' ng-show='show'><div class='ng-modal-overlay' ng-click='hideModal()'></div><div class='ng-modal-dialog' ng-style='dialogStyle'><div class='ng-modal-close' ng-click='hideModal()'>X</div><div class='ng-modal-dialog-content' ng-transclude></div></div></div>"
我想將它添加到一個函數來刪除一些$範圍。但瀏覽器顯示錯誤,它無法找到變量$ scope.types.individual。
我只是試着自己學習AngularJS,還是有一些問題。
'$刪除sope.types.individual;'?或'刪除$ scope.types.individual;'?? – DilumN
正如我正確理解你的'類型'是在你的控制器上?所以你可以'刪除$ scope。$ parent.types.individual;'但是你似乎正在嘗試實現某些東西並且使用非角度的方式來做到這一點 – devqon
@DumumN是的,$ scope,抱歉..但是我仍然有相同的錯誤 –