我已經看過幾篇文章,但仍然無法弄清楚。父範圍沒有從選擇指令更新ng-change從指令
我無法從指令中更新父範圍。我已閱讀文章說範圍值不應該是原始的,而應該是一個對象,但仍然無法弄清楚爲什麼這不起作用。
angular.module('moduleMihai').controller('someController',
['$scope', '$http', function ($scope, $http) {
$scope.durations = [{
field: 'yearly',
title: 'Yearly'
}, {
field: 'monthly',
title: 'Monthly'
}, {
field: 'weekly',
title: 'Weekly'
}];
$scope.selectedDuration = $scope.durations[0];
$scope.handleDurationSelection = function() {
console.log($scope.selectedDuration.field + ' selected');
$scope.someData.title[0] = "SOMETHING ELSE!!";
};
$scope.someData= {
title: ['Value1', 'Value2', 'Value3'] };
}]);
指令沒有在它的任何東西:
angular.module("awaCommon").directive("durationSelection", [
function() {
return {
scope: {}, // tried removing this as well as seen in some articles
restrict: "E",
templateUrl: "duration-selection.html",
link: function ($scope, $element, $attr) {
}
}
}
]);
期間,selection.html以下其中包含選擇:
<div ng-controller="someController">
<div>
Child: {{someData.title[0]}}
<select
ng-options="item.title for item in durations"
ng-model="selectedDuration"
ng-change="handleDurationSelection()">
</select>
</div>
所以這上面的值在Child中:{{someData.title [0]}} - 在選擇值時正確更新。但是,一個在這裏 - 家長:{{someData.title [0]}},在主要路線是不是:
<div ng-controller="someController">
<div>
Parent: {{someData.title[0]}}
<duration-selection></duration-selection>
</div>
我需要父範圍,以更新不同的更新指令
對角V1,使用'angularjs'標籤。 'angular'標籤適用於Angular v2 +。這樣你就會吸引合適觀衆的注意力。 – DeborahK
確定,會做謝謝。 –