Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.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 将子控制器的作用域值访问到父控制器 //父控制器(嵌套控制器) var appoptomelist=angular.module('OptometristModule',['angularFileUpload']); Appoptomeist.controller('OptometeristController',函数($scope,$http){ }); //用于文件上载的子控制器 appoptomelist.controller('ChildController',函数($scope,$http,$upload){ $scope.onFileSelect=函数($files){ $scope.message=“”; 对于(变量i=0;i_Angularjs_Angularjs Scope - Fatal编程技术网

Angularjs 将子控制器的作用域值访问到父控制器 //父控制器(嵌套控制器) var appoptomelist=angular.module('OptometristModule',['angularFileUpload']); Appoptomeist.controller('OptometeristController',函数($scope,$http){ }); //用于文件上载的子控制器 appoptomelist.controller('ChildController',函数($scope,$http,$upload){ $scope.onFileSelect=函数($files){ $scope.message=“”; 对于(变量i=0;i

Angularjs 将子控制器的作用域值访问到父控制器 //父控制器(嵌套控制器) var appoptomelist=angular.module('OptometristModule',['angularFileUpload']); Appoptomeist.controller('OptometeristController',函数($scope,$http){ }); //用于文件上载的子控制器 appoptomelist.controller('ChildController',函数($scope,$http,$upload){ $scope.onFileSelect=函数($files){ $scope.message=“”; 对于(变量i=0;i,angularjs,angularjs-scope,Angularjs,Angularjs Scope,phpfile: //parent controller (nested controller) var appOptometrist = angular.module('OptometristModule', ['angularFileUpload']); appOptometrist.controller('OptometristController', function ($scope, $http) { }); //child cont

phpfile:

    //parent controller (nested controller)
    var appOptometrist = angular.module('OptometristModule', ['angularFileUpload']); 



    appOptometrist.controller('OptometristController', function ($scope, $http) {





    });

//child controller for file upload
    appOptometrist.controller('ChildController', function ($scope, $http, $upload) {

        $scope.onFileSelect = function($files) {
                    $scope.message = "";
                    for (var i = 0; i < $files.length; i++) {
                        var file = $files[i];
                        console.log(file);
                        $scope.upload = $upload.upload({
                            url: 'upload.php',
                            method: 'POST',
                            file: file
                        }).success(function(data, status, headers, config) {
                            $scope.message = data;                
                        }).error(function(data, status) {
                            $scope.message = data;
                        });
                    }
                };



    });

使用服务,我们可以通过设置和获取来使用变量。在控制器的注入参数中注入此服务

<body class="nav-md" ng-app="OptometristModule">

<div class="container body" ng-controller="OptometristController">

<div ng-controller="ChildController">
<input type="file" id="i_file" name="file" ng-file-select="onFileSelect($files)" multiple />
</div>
另一种方法是broard cast&on

 angular.module('appOptometrist')
    .service('common', [function() {
        this.criteria = {};
        this.setCriteria = function(criteria) {
            this.criteria = criteria;
        };
        this.getCriteria = function() {
            this.criteria.limit = 1;
            return this.criteria;
        };
    }]);

如果您需要使用服务将数据从一个控制器传递到另一个控制器,那么具有父/子关系的事件实际上在子控制器到父控制器之间就足够了,而不是从
$rootScope
向下广播。Ok skubski。我们将在这里使用
$emit
。我改变了答案。谢谢你的建议
            appOptometrist.controller('ChildController', function($scope, $http, $upload) {
                $scope.$emit('criteria');
                :
            }

            appOptometrist.controller('OptometristController', function($scope, $http) {
                $scope.$on('criteria', function() {:
                });
            });