我寫了一個需要更新父範圍的角度指令。Angular指令 - 當另一個指令也是隔離範圍時更新父範圍
angular.module('app').directive('googlePlace', function() {
return {
restrict: 'A',
require: 'ngModel',
link: function ($scope, element, attributes, model) {
$scope.property1 = 'some val';
$scope.property2 = 'another val';
$scope.$apply();
};
});
但在我控制我這樣做:
MyCtrl = function($scope){
$scope.doSave = function(){
// do some logic
console.log($scope.property1);
console.log($scope.property2);
}
}
當doSave
運行,我在我的控制檯獲得未定義的值。如何在不隔離範圍的情況下將其應用於家長範圍。我沒有這個選項,因爲同一元素上的另一個指令隔離範圍。