Giter Club home page Giter Club logo

Comments (11)

btford avatar btford commented on June 3, 2024

Why do you want to use a directive for this? What meaning does it have for a <modal> to be within some position in the DOM?

from angular-modal.

stryju avatar stryju commented on June 3, 2024

scenario:

i have a "page" on which i want to display few different forms in a modal window and use their results on this page

also, i want to use the modal windows as a replacement for window.confirm(), window.prompt() and window.alert() but the messages should reside outside of JS itself - in HTML, so their content could differ

or is my approach a bad idea in general? :)

from angular-modal.

stryju avatar stryju commented on June 3, 2024

having it in some position in the DOM would be only initial - ideally, the directive would take it "out" of the DOM transcluding the content and making it "Ready to use" as needed, so

<modal ng:controller="alertModal">
  hi there! I'm {{ name }}
</modal>

would be, ideally, available via alertModal.activate({ name: 'foo' }); somewhere within a page controller

from angular-modal.

btford avatar btford commented on June 3, 2024

Why not have the HTML for the modal in a separate HTML file rather than meaninglessly nested on the page?

From everything you said, it makes more sense for the modal to be a service than a directive.

from angular-modal.

stryju avatar stryju commented on June 3, 2024

that's the problem - html could be different for every possible situation
different alerts, different prompts, different content - like a whole form etc

i want dont want to end up with 20 different services for modals

from angular-modal.

btford avatar btford commented on June 3, 2024

But you're okay with having a directive used 20 different times? How is that any better?

from angular-modal.

stryju avatar stryju commented on June 3, 2024

well, that's actually my question - is it better to have 20 services for each possible scenario or have one "flexible" directive?

sorry if i'm poking around a really obvious solution - new to angular and trying different approaches to see what works best :)

from angular-modal.

btford avatar btford commented on June 3, 2024

20 services for each possible scenario or have one "flexible" directive

This is a false dichotomy. You could have one "flexible" service or 20 different directives. If you want to parameterize templates, you can use locals and ng-include. There are many ways to reduce duplicated code with the service approach, if that's your concern.

I'd encourage you to think critically about the architecture of your app, especially with regards to what it means to be a service versus a directive. I suspect your proposed solution will be cumbersome to test, for instance.

Try the service-based approach. If you run into a problem with it, post a jsfiddle or plunkr and we can walk through it.

from angular-modal.

stryju avatar stryju commented on June 3, 2024

sweet, thanks

from angular-modal.

stryju avatar stryju commented on June 3, 2024

you were right - ended up with 6 services in total (for now) and it's all good

thanks for your time spent on explaining it to me - much appreciated 🍻

from angular-modal.

btford avatar btford commented on June 3, 2024

anytime :) 🍻

from angular-modal.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.