N
N
nepster-web2014-04-20 14:19:55
JavaScript
nepster-web, 2014-04-20 14:19:55

Angularjs, How to pass data to bootstrap modal?

I'm dabbling in Angularjs and having a problem passing data to a modal window.

angular.module('app', ['ui.bootstrap.dialog'])
    .factory('apiModal', function ($http, $q) {
       return {
        
            // Открываем модальное окно 
            openWindow: function ($scope, $dialog, $window, apiModal) {
                
                $scope.test = {name: 'OK'};
                
                var options = {
                    backdrop: true,
                    keyboard: true,                    
                    controller: 'dialogModal',
                    template: ':{{test.name}}',
                    //templateUrl: 'view.html',
                };
                
                var dialog = $dialog.dialog(options);
                dialog.open().then(function(result) {
                    
              
                    if (result === 1) {
                        apiModal.request();
                    }
                });
            },
            
            // Запрос на сервер
            request: function (data) {
            
                 alert('Отправляем данные с помощью AJAX');
                 return false;
                 
            } 
       }     
   })
    .controller('Ctrl', function ($scope, $dialog, $window, apiModal) {
        // Открываем модальное окно
        $scope.openWindow = function() {
            apiModal.openWindow($scope, $dialog, $window, apiModal);
        };
   })
   
   .controller('dialogModal', function($scope, dialog) {
        $scope.close = function(result) {
            dialog.close(result);
        };
    });

I did something like this:
$scope.test = {name: 'OK'};
In the window I try to get
{{test.name}}
But I get a void. Can you please tell me how to pass data to the modal window?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Insayt, 2014-06-13
@Insayt

Make sure the window layout is in the correct scope

A
AtNovember, 2015-08-08
@AtNovember

Tell me, are the quotes in your code in the same sequence?

template: ':{{test.name}}',

instead of
Could this be the problem?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question