Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/302.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/0/asp.net-core/3.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
javascript/angular中的类继承_Javascript_C#_Angularjs_Inheritance - Fatal编程技术网

javascript/angular中的类继承

javascript/angular中的类继承,javascript,c#,angularjs,inheritance,Javascript,C#,Angularjs,Inheritance,我正在做我的hello world项目。我有两个页面,我们称之为“配置”和“添加配置”*.html。每个控制器都有自己的控制器,如下所示: angular.module('MissionControlApp').controller('ConfigController', ConfigController); angular.module('MissionControlApp').controller('AddConfigController', AddConfigController);

我正在做我的hello world项目。我有两个页面,我们称之为“配置”和“添加配置”*.html。每个控制器都有自己的控制器,如下所示:

angular.module('MissionControlApp').controller('ConfigController', ConfigController);

angular.module('MissionControlApp').controller('AddConfigController', AddConfigController);
现在,每个控制器都有一些非常重叠的属性:

function ConfigController($routeParams, ConfigFactory, $window){
    var vm = this;
    vm.status;
    vm.projectId = $routeParams.projectId;
    vm.selectedProject;
    vm.configurations;
    vm.selectedConfig;
    vm.selectedRecords;
    vm.filteredConfig;
    vm.newFile;
    vm.fileWarningMsg = '';

vm.addFile = function(){
        var filePath = vm.newFile;
        var encodedUri = encodeURIComponent(filePath);
        vm.fileWarningMsg='';

        ConfigFactory
            .getByEncodedUri(encodedUri).then(function(response){
                var configFound = response.data;
                var configNames = '';
                var configMatched = false;
                if(response.status === 200 && configFound.length > 0){
                    //find an exact match from text search result
                    for(var i = 0; i < configFound.length; i++) {
                        var config = configFound[i];
                        for(var j=0; j<config.files.length; j++){
                            var file = config.files[j];
                            if(file.centralPath.toLowerCase() === filePath.toLowerCase()){
                                configMatched = true;
                                configNames += ' [' + config.name + '] ';
                                break;
                            }
                        }
                    }
                }
                if(configMatched){
                    vm.fileWarningMsg = 'Warning! File already exists in other configurations.\n' + configNames;
                } else if(filePath.length > 0 && filePath.includes('.rvt')){
                    var file1 = { centralPath: filePath };
                    vm.selectedConfig.files.push(file1);
                    vm.newFile = '';
                } else{
                    vm.fileWarningMsg = 'Warning! Please enter a valid file.';
                }

            }, function(error){
                vm.status = 'Unable to get configuration data: ' + error.message;
            });

    };

既然您询问了有关继承的问题,并且似乎正在使用ECMAScript 5,那么让我建议您看看。具体地说,是

也就是说,在AngularJS中,更好的解决方案是创建一个管理文件或配置的应用程序,并将
addFile
函数放在其中。这样,两个控制器都可以注入服务,并在需要添加文件时调用相同的函数。同样,可能需要访问此功能的其他服务和控制器也可以将其注入

function AddConfigController($routeParams, ConfigFactory, $window){
    var vm = this;
    vm.status;
    vm.projectId = $routeParams.projectId;
    vm.selectedProject = {};
    vm.newConfig = {};
    vm.newFile;
    vm.fileWarningMsg = '';

vm.addFile = function(){
        var filePath = vm.newFile;
        var encodedUri = encodeURIComponent(filePath);
        vm.fileWarningMsg='';

        ConfigFactory
            .getByEncodedUri(encodedUri).then(function(response){
                var configFound = response.data;
                var configNames = '';
                var configMatched = false;
                if(response.status === 200 && configFound.length > 0){
                    //find an exact match from text search result
                    for(var i = 0; i < configFound.length; i++) {
                        var config = configFound[i];
                        for(var j=0; j<config.files.length; j++){
                            var file = config.files[j];
                            if(file.centralPath.toLowerCase() === filePath.toLowerCase()){
                                configMatched = true;
                                configNames += ' [' + config.name + '] ';
                                break;
                            }
                        }
                    }
                }
                if(configMatched){
                    vm.fileWarningMsg = 'Warning! File already exists in other configurations.\n' + configNames;
                } else if(filePath.length > 0 && filePath.includes('.rvt')){
                    var file1 = { centralPath: filePath };
                    vm.selectedConfig.files.push(file1);
                    vm.newFile = '';
                } else{
                    vm.fileWarningMsg = 'Warning! Please enter a valid file.';
                }

            }, function(error){
                vm.status = 'Unable to get configuration data: ' + error.message;
            });

    };