Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 指令内的更改指令变量不起作用_Angularjs_Angularjs Directive_Angularjs Controller - Fatal编程技术网

Angularjs 指令内的更改指令变量不起作用

Angularjs 指令内的更改指令变量不起作用,angularjs,angularjs-directive,angularjs-controller,Angularjs,Angularjs Directive,Angularjs Controller,我试图更改指令中的控制器变量,以下是我的代码: 主控制器是: angular.module("app").controller('vehicleManagementController', ['$scope', 'toastr', '$filter' , function ($scope, toastr, $filter) { ..... $scope.filteredDevices = //Some List $scope.allDevices = []; } }])

我试图更改指令中的控制器变量,以下是我的代码:

主控制器是:

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.filteredevices
,但当我更改其值时,它在主控制器中不会更改。我做错了什么?

如果要保存对父控制器作用域的更改,则应使用

范围:假

将指令更改为:

     return {
       restrict: "E",
       controller: 'myDirectiveController',
       scope: false,
       templateUrl: '/app/templates/advanceSearchDirective.html'
   };

能否添加JSFIDLE或/app/templates/advanceSearchDirective.html的内容?@Michelem模板中没有任何相关内容。是否替换
$scope.filteredevices=[]
$scope.filteredevices.length=0帮助?是$scope.$apply();Nessery是给你的吗?我不理解这一刻,为什么会出现——当您更改作用域中的变量时,$apply会自动调用。这就是为什么angular说“apply ready runninfg”。通常,它用于通知angular有关非角度更改的信息,如jQuery插件值。顺便问一下,控制台中是否有任何消息?