你能在不覆盖数据的情况下使用相同的视图和角度控制器吗?

时间:2021-12-03 21:04:53

I have an application using a PDF viewer-pdf angularjs made, this viewer uses a html template with its own controller angularjs, this viewer want to use it in different catalogs (ie it is global) viewer, I work well when I open one PDF catalog and position, but when you open another I unlocked the other loads the pdf in the previous window and no where open, ie data overwrites me Is there any way to resolve this, open the same viewer in several catalogs without affecting others?

我有一个应用程序使用一个PDF viewer-pdf angularjs,这个查看器使用html模板有自己的控制器angularjs,观众想要使用它在不同的目录(全球)观众,我工作得很好,当我打开一个PDF目录和位置,但当你打开另一个我打开其他加载PDF在前面的窗口,没有打开,即数据覆盖我有什么方法可以解决这个问题,开放在几个目录而不影响其他观众一样吗?

2 个解决方案

#1


0  

If you make the PDF viewer a directive you should be able to achieve this because directives operate within their own scope.

如果您让PDF查看器是一个指令,您应该能够实现这一点,因为指令在它们自己的范围内运行。

#2


0  

That's why I created a service as shown:

这就是为什么我创建了一个服务,如下所示:

angular.module('myModule',['pdf']).service('pdfService', function () {

    var pdfURL = "";

    var defineURL = function (url) {
        pdfURL = url;
    };

    var getURL = function () {
        return pdfURL;
    };

    return {
        defineURL: defineURL,
        getURL: getURL
    };

}).controller('DocControlador', ['$scope', 'pdfService', function ($scope, pdfService) {

    $scope.pdfName = '';
    $scope.pdfUrl = pdfService.getURL(); 
    $scope.scroll = 0;
    $scope.loading = 'cargando...';

    $scope.getNavStyle = function (scroll) {
        if (scroll > 100) return 'pdf-controls fixed';
        else return 'pdf-controls';
    }

    $scope.onError = function (error) {
        console.log(error);
    }

    $scope.onLoad = function () {
        $scope.loading = '';
    }

    $scope.onProgress = function (progress) {
        console.log(progress);
    }

}])

and here I pass I assign values to the variables of service from another controller:

这里,我给另一个控制器的服务变量赋值:

pdfService.defineURL("\\Files\\1\\Charts\\" + $scope.fileName);

#1


0  

If you make the PDF viewer a directive you should be able to achieve this because directives operate within their own scope.

如果您让PDF查看器是一个指令,您应该能够实现这一点,因为指令在它们自己的范围内运行。

#2


0  

That's why I created a service as shown:

这就是为什么我创建了一个服务,如下所示:

angular.module('myModule',['pdf']).service('pdfService', function () {

    var pdfURL = "";

    var defineURL = function (url) {
        pdfURL = url;
    };

    var getURL = function () {
        return pdfURL;
    };

    return {
        defineURL: defineURL,
        getURL: getURL
    };

}).controller('DocControlador', ['$scope', 'pdfService', function ($scope, pdfService) {

    $scope.pdfName = '';
    $scope.pdfUrl = pdfService.getURL(); 
    $scope.scroll = 0;
    $scope.loading = 'cargando...';

    $scope.getNavStyle = function (scroll) {
        if (scroll > 100) return 'pdf-controls fixed';
        else return 'pdf-controls';
    }

    $scope.onError = function (error) {
        console.log(error);
    }

    $scope.onLoad = function () {
        $scope.loading = '';
    }

    $scope.onProgress = function (progress) {
        console.log(progress);
    }

}])

and here I pass I assign values to the variables of service from another controller:

这里,我给另一个控制器的服务变量赋值:

pdfService.defineURL("\\Files\\1\\Charts\\" + $scope.fileName);