ディレクティブ内のコントローラー変数を変更しようとしています。これが私のコードです。
メインコントローラーは:
angular.module("app").controller('vehicleManagementController', ['$scope', 'toastr', '$filter' ,
function ($scope, toastr, $filter) {
.....
$scope.filteredDevices = //Some List
$scope.allDevices = [];
}
}]);
ディレクティブは:
angular.module('app').directive('advanceSearchDirective', ['deviceAdvancedSearchService', 'mapService', function (deviceAdvancedSearchService, mapService) {
return {
restrict: "E",
controller: 'myDirectiveController',
scope: { filteredDevices: '=filteredDevices' },
templateUrl: '/app/templates/advanceSearchDirective.html'
};
}]);
angular.module("app").controller(myDirectiveController( $scope) {
$scope.search = function() {
$scope.filteredDevices = [];
$scope.$apply();
}
});
問題は、このエラーによってapply()メソッドの実行に失敗したことです。そしてここで私はそれをどのように使用していますか:
<advance-search-directive filtered-devices="filteredDevices" model="$parent"></advance-search-directive>
$scope.filteredDevices
ディレクティブコントローラーの内部にアクセスできますが、その値を変更してもメインコントローラーでは変更されません。私は何が間違っているのですか?
親コントローラースコープに変更を保存する場合は、次を使用する必要があります
スコープ:false、
ディレクティブを:に変更します。
return {
restrict: "E",
controller: 'myDirectiveController',
scope: false,
templateUrl: '/app/templates/advanceSearchDirective.html'
};
ここに役立つ記事があります。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加