我已经看过几篇文章,但仍然无法弄清楚。父范围没有从选择指令更新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
确定,会做谢谢。 –