Ways to extract a result from a modal

I'm currently implementing a basic todo list feature in my ionic vs1/angularjs project and I want to integrate it with the Ionic modal for launching this list smoothly. Since I need this functionality accessible from any part of the application, I sought out a solution for achieving this goal. Discovering an insightful article at https://medium.com/@saniyusuf/create-an-isolate-modal-with-ionic-v1-b4cf73f05727, I followed the instructions to create a factory that could be initiated from various controllers - which turned out to be highly beneficial. However, there's a slight challenge regarding enabling users to add and delete tasks within the todo list. To address this, I decided to store this information on Firebase and constructed another factory responsible for all CRUD (Create, Read, Update, Delete) operations related to the ToDo list. Now equipped with a factory for launching the modal and one for handling Firebase interactions, I managed to incorporate the CRUD operations within the modal launcher. But an issue persists - how do I retrieve the value entered in the input field?

Modal Launcher

 angular.module('formulaWizard')
   .factory('IsolateModal', IsolateModal)
 IsolateModal.$inject = ['$rootScope', '$ionicModal', '__ToDo', 
 '$window'];

function IsolateModal($rootScope, $ionicModal, __ToDo, $window) {


var modalsIsolateScope = $rootScope.$new();
var currentUser = $rootScope.currentUser || JSON.parse($window.sessionStorage.getItem('payload')); 

var isolateModal = {
  open: open
};

function open() {
  $ionicModal.fromTemplateUrl(
    'app/to-do/toDo.html',
    {
      scope: modalsIsolateScope
    }
  )
    .then(function (modalInstance) {
      modalsIsolateScope.close = function () {
        closeAndRemove(modalInstance);
      },
      modalsIsolateScope.add = function(){
        addTodo(modalInstance);
      };
      return modalInstance.show();
  });

}

function closeAndRemove(modalInstance) {
  return modalInstance.hide()
    .then(function () {
      return modalInstance.remove();
    });
}
  function addTodo(modalInstance) {
    var i = modalInstance

      __ToDo.toDo($scope.input)
        .then(function(result) {
          $scope.input = {};
          // Reload our todos, not super cool
          getAllTodos();
        });
    }


   return isolateModal;

 }

My Data Factory

 angular.module('formulaWizard')
.factory('__ToDo', function(__Refs, $q) {
return {
  toDo: function(id, userObject, cb) {
    var toDo = __Refs.userNotes.child(id).push(userObject);
    __Refs.userNotes.child(id).child(newToDo.key()).update({ toDo_id: 
 newToDo.key() }).then(function(response) {
      cb(response);
    }, function(e) {
      console.error('error occured');
    });;
  },
  updateToDo: function(userId, toDoId, userObject, cb) {
    var x = 
  __Refs.userNotes.child(userId).child(toDoId).update(userObject)
  .then(function(response) {
      cb(response);
    }, function(e) {
      console.error('Error editing');
    });
  },
  deleteToDo: function(userId, toDoId, cb) {
    __Refs.userNotes.child(userId).child(toDoId).remove(function(error) {
      if (error) {
        console.error(error);
      } else {
        cb();
      }
    });
  },
  getuserNotes: function(id, cb) {
    __Refs.userNotes.child(id).on('value', function(response) {
      cb(response.val());
    });
  }

 }
});

Call From Controller

$scope.openModal = function () {
        IsolateModal.open();

    };

Html

<ion-modal-view>
<ion-header-bar class="bar-stable">
<h1 class="title">My List</h1>
<button class="button icon ion-close-round button-icon" 
   ng-click="close()"></button>
 </ion-header-bar>
  <ion-content>
   <div class="list card" style="width:100%; margin-left:0;">
   <div class="item item-body">
    <div class="item-input-inset">
      <label class="item-input-wrapper">
        <input id="newInput" type="text" placeholder="New Todo" 
         ng-model="input.name">
      </label>
      <button class="button button-balanced button-small" ng-click="add()">
        Add Todo
           </button>
        </div>
         <ion-list can-swipe="true">
           <ion-item ng-repeat="item in todos">
             {{item.name}}
             <ion-option-button class="button-assertive" ng-click="deleteTodo(item.id)">
               Delete
              </ion-option-button>
           </ion-item>
         </ion-list>
       </div>
      </div>
   </ion-content>
 </ion-modal-view>

How can I extract the input value from the HTML page into the factory?

Thank you

Answer №1

How can I access the input value?

Here is the function that returns a promise:

function retrieve() {
   ̲r̲e̲t̲u̲r̲n $ionicModal.fromTemplateUrl(
    'app/to-do/toDo.html',
    {
      scope: modalsIsolatedScope
    }
  )
    .then(function (modalInstance) {
      modalsIsolatedScope.close = function () {
        closeAndDestroy(modalInstance);
      },
      modalsIsolatedScope.add = function(){
        addTask(modalInstance);
      };
      return modalInstance.display();
  });

}

Next, get the value from the returned promise:

$scope.openDialog = function () {
    var assure = IsolateModel.retrieve();
    assurance.then(function(data) {
        console.log(data);
    });
    return assure;
};

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Full screen background slideshow is a visually stunning way to

On the hunt for a fullscreen background slideshow that works in any resolution. So far, I've only come across options with fixed sizes. Is there a way to create a slideshow with a fade effect (and resize images to fit full screen) in the background? ...

I am trying to customize the colors of each Y-axis grid line in Chart.JS based on their corresponding values

Utilizing MVC 4.0 and chart.JS for graph generation, I have successfully implemented horizontal lines on the Y axis using the following property: scaleShowGridLines = true; scaleShowHorizontalLines: true, //Boolean - Whether to show vertical lines (except ...

I am facing a dilemma where React Native seems to be disregarding all the container styles I

Here is the code snippet I am working on: import React from 'react'; import { StyleSheet, Text, View, TouchableOpacity } from 'react-native'; export default class ShortcutsHome extends React.Component { render() { return ( ...

Error message: "Zombie.js encountered a jQuery Load Error - 'j.getClientRects is not a function'"

When I came across this Stack Overflow post, it didn't seem to address the same issue I am facing. My current objective is to use Mocha and Zombie.js for testing on my Node.js website. The main test I want to run involves checking if a user can be c ...

Consolidate test outcomes from various nodes in the stack into a single graph

Nowadays, web applications consist of a variety of different technology stacks. Developers utilize languages like Ruby, Python, PHP, JavaScript, and C for the backend, as well as frameworks such as AngularJS and EmberJS for MVC/client-side code. To ensure ...

Removing the gap between the clicked point and the draw point in Html5 canvas

To better understand my issue, please refer to the image linked below: In the image, you can see that when I scroll down and click on the canvas to point a position, it creates space between the clicked point and where the line is drawn. Below is the cod ...

Phonegap failing to trigger service method for Ajax requests

My AJAX call looks like this: $.ajax({ type: "POST", url: "http://localhost:95/MobileEcomm/Service1.svc/validateLogin", crossDomain: true, data:{ 'EmailID':EmailID, 'Password':Password}, success: ...

Experiencing the error message "globals is not defined" despite the fact that the globals variable is already defined

Currently, I am working on reorganizing the routes in my web application. I made the mistake of defining all the routes in index.js, and now I'm facing an unusual issue in some files. I keep getting errors stating that the "globals" variable is undefi ...

What is the best way to execute Jest tests concurrently using the VSCode extension?

Running the Jest tests in band is essential to prevent errors from occurring. However, I am unsure of how to resolve this issue. The tests run smoothly when executed through the command line. ...

Confirming the presence of an image using jQuery without enforcing it as mandatory

Situation: In my setup, I maintain a database that holds details about various items. Currently, I utilize a dynamic form to retrieve and exhibit the existing information on any item stored in the database. Any modifications made on the form are promptly ...

Apply active class to a link element in React JS

Creating a component that displays menus from an array import React from 'react' import { Link, browserHistory,IndexLink } from 'react-router' $( document ).ready(function() { $( "ul.tabs li a" ).first().addClass("current"); ...

Using Socket.emit in Ionic may not function as expected

Currently, I'm in the process of establishing a socket connection between my Ionic application and a socket server that I've constructed. The socket connection seems to encounter issues specifically when running the app on an iOS simulator u ...

Steps for showcasing a automated slideshow

I'm currently working on creating a slideshow that automatically displays multiple images. While the first image shows up just fine, it doesn't seem to transition to the next one. var currentSlide = 0; displaySlides(); functio ...

What is the best approach to implement pagination in the UI-Bootstrap Typeahead Directive?

In my current Angular Project, I am utilizing the UI-Bootstrap's Typeahead Directive for a specific purpose. However, I am encountering an issue when dealing with a large amount of similar data using this directive. It seems that displaying only the ...

Searching with Sequelize for an indirect relationship: How can it be done?

Within my database, there exists a relationship between Users and Roles. A User can have multiple Roles assigned to them. These Roles are connected to Activities in such a way that they can be associated with many different activities. This association all ...

Encountering an issue with eslint-loader in a new VueJS project: TypeError - eslint.CLIEngine is not recognized as

Embarking on a fresh VueJS venture with WebStorm. A brand new VueJS project has been established, NPM upgraded, Vuetify added, and upon server initiation, an error pops up: ERROR Failed to compile with 1 errors ...

Is there a way to conceal an element using identical markup with jquery?

Having trouble with two custom dropdown lists that share the same markup. Ideally, only one should be visible at a time. However, both are currently opening simultaneously. Additionally, I need them to close when clicking outside of the list. It's ne ...

I'm struggling to retrieve a specific column of data from a JSON file. Does anyone know how to do this successfully?

I have a JSON file with various columns, but I only want to display the rdid column. I am new to learning node and still trying to figure things out. data [ {"edid":"r7vr8r", "rdid":"86596", "rssi":&qu ...

Enabling deep linking with $locationProvider.html5Mode in AngularJS

After activating html5Mode in AngularJS with $locationProvider.html5Mode(true), the navigation appears to be off when arriving on a deeper page within the site. For instance: http://www.site.com When navigating to the root, all links on the site are ...

What is the best way to include multiple entries in a select2 form using ajaxform?

select2/3.5.2/ I had to repost this because my initial post was not formatting correctly. The tools in use are: A select2 form field that allows searching through multiple records A bootstrap popup modal containing a form for entering a new record if i ...