-
Notifications
You must be signed in to change notification settings - Fork 6.7k
$modal.open
compatibility with component (angular.component
method)
#5683
Comments
I believe this would force us to only support Angular 1.5+ and i'm not sure we're ready to go there yet. |
@icfantv Is there any issue with coexistence of both variants? Could't proposed API coexist with current one? |
@zdychacek, i don't know. this would require investigation if this is, in fact, something we want to support. but we need to have the discussion first. |
I'm not against this, but we'll have to determine at what stage we want to implement this. We could implement it now, and have code where this only applies to angular 1.5+, but that adds bloat for those using 1.4. |
I'm trying to use existing modal with component this way:
Then in my component:
However, it doesn't work :( this.message in component controller is empty. I'm not sure why. ----- edit I've just found the problem -> arrow function in controller! :) To make it work:
|
@Olgagr there should be nothing wrong with having an arrow function if your transpiler is working correctly. Arrow functions are simply rewritten as you have defined above. I would encourage you to look at your transpiled code with the arrow function and see what it's generating. |
@icfantv I think in this case it makes difference because $uibModal.open is run in controller class of other component. To show wider context:
Can you see the problem here ? If I use lambda, this will be PublicationController instance. |
@Olgagr, i don't follow, i use arrow functions inside my ES6 classes all the time. the only thing I don't do is specify a function for my |
@icfantv And this is a difference :) Arrow functions are not compiled to the same code as "normal" functions. See the difference: http://bit.ly/1S41ZuP |
ah, ok. good to know. thanks. |
@Olgagr You can't use arrow function in this case because arrow functions have lexical scope which means that |
I'm not sure this proposal has much sense or even necessary. The example @zdychacek gives can already be expressed with existing syntax:
Existing syntax is very flexible and can already be used with components. At the same time, proposal means introducing two more config properties ( So there are questions that are not very obvious. |
@dfsq Yes, I know about it (arrow functions). We've just discussed this above :) |
I agree with @dfsq . I also use the existing syntax with components and so far it works pretty well. |
@dfsq Hi, I would like to know, how do you access I can't see any other solution than passing it explicitly via component's
|
@zdychacek Do you need the whole modal instance ? For example, to have access to close or dismiss methods you can also pass just them as bindings:
and then in your component bindings:
|
@Olgagr No I don't need it whole. I've only tried to model the behaviour as similar as possible to the current one and that's to have an option to inject But I can live with the solution mentionted above :) |
On thing that is surprising to me: bindings are not updated. Let's say I open modal like this:
my-modal component has bindings:
Now, at some point, when modal is already opened, inside SomeComponentController this.pages changes. However, inside my-modal component this pages binding is not refreshed ($onChanges method is not called). This is surprising. It should be live binding after all, right ? |
@Olgagr This should not happen, most likely there is something with the way you are updating Here is a quick demo: http://plnkr.co/edit/XeqlnwjePvSTn0pXPaPz?p=preview |
@dfsq Thanks for demo! Yes, you're right. The bindings should be updated. |
@dfsq I was able to reproduce the issue. Here is modified your plunker example: http://plnkr.co/edit/Jq6fwT?p=preview Instead of pushing to array, I'm changing reference. As you can see the modal binding is not updated any more. Also $onChanges hook is not fired(it is only fired once, at the beginning but not after update). When you do the same but with a regular component the binding is updated. Also $onChanges hook is fired: https://plnkr.co/edit/Rf82S9fCvA35R1kBMAc5?p=preview I'm trying to understand why this is happening. |
@Olgagr , you use one-way binding '<'. For your controller to see the updated reference, you need to use two-way binding: '='. |
@dietergeerts Hmm, why ? One way binding is updated from parent to child. Anyway, I've changed one-way binding to two-way binding but reference is still not updated: http://plnkr.co/edit/aQa0YU?p=preview |
@Olgagr, I think I misunderstood you then, I thought the change wasn't going back to the parent. |
I went around it like this, keeps the component ignorant of being shown in a dialog.
|
@wesleycho so this will be done and it should work with ng1.4.x with directives of type |
Yes. |
@wesleycho will this change be propagated from say version 0.14.3 or will it be available only in latest library vesion? |
@jeserkin, we do not back port changes. We only release new, latest versions. We simply don't have the manpower as volunteers to support multiple versions. |
Does @zdychacek API proposal is the way we want to implement this ? |
@Olgagr as far as I can tell, it can't be just passed into template. Component/Directive of type element must be specified. I would assume, that Since I'm lately more in favor of component based approach, then I'm not sure, how good would it be to leave both approaches available, seems enforcing newer supported way is more correct. |
Here is the API signature to be implemented - it will be used like $modal.open({
component: 'myComponent'
}); where One will be able to use module.component('myComponent', {
controller: 'MyController',
bindings: {
$resolve: '<'
}
}); If this sounds sensible, I will look to implement this within the next few weeks (or someone else can implement it). |
@wesleycho What about component lifecycle and & bindings ? Will it work with this solution ? |
@Olgagr I was considering that - my assumption is that component users will eschew using Can you give an example as to how you were thinking of using this? |
@wesleycho Yes, I can give you very specific example, because I have an Angular application that uses almost only components. I have a WYSIWYG editor, where user can put image. When he clicks image the modal window is shown, where user can crop image. The definition of this cropping component (that I would like to load in modal window) looks like this:
As you can see, this component is not responsible for saving changes on image. It should delegate this to parent component. On the other hand, parent component should notify this component, if there are any errors when saving cropped image. Right now, I'm calling this component from parent this way:
And this is working, except that savingErrors is never updated ($onChanges is not fired). |
Thank you for this example. This use case would demand the library not make the assumption - I'm ok with that. We will need to support a bindings object then, which will look like this: $uibModal.open({
component: 'myComponent',
controller: 'MyModalController',
bindings: {
myAttribute: 'myStringReferenceTo$scopeVariable'
}
}); The bindings object here will just add the attributes and values to the component, where the attribute name will be the properties and the values will be the values of the object. Does this sound amenable? As for |
@wesleycho Lifecycle hooks should work in the component you assign to the modal. They are so useful and if the component doesn't fire them, it will be confusing. |
So they're not working in the component currently when in use? Can you file another issue, that sounds like a bug. |
@wesleycho I'd already done it (#5881), but the issue was closed as duplicate of this discussion. |
Hi, i'm new to Angular and this angular-ui-bootstrap library, my project uses the new component structure of Angular 1.5. Can someone please summarise this discussion for me? I can sort of create a component modal but there are some aspects of data binding that wont work? Is there a concise example of how I would use it for now until the feature is implemented in 2.1? Thanks! Never mind! Looks like there is a SO thread here: |
This isn't the place for such questions. There are examples in this issue on how to do this - otherwise, it is encouraged to ask help questions in places such as Stack Overflow, IRC, Gitter, or Slack. |
@wesleycho will this new component based solution still need controller to be assigned in modal open action? Component as well as it predecessor directive of type element ( $uibModal.open({
component: 'myComponent',
bindings: { // Previous resolve property (I assume)
myAttribute: 'myStringReferenceTo$scopeVariable'
}
}); |
@jeserkin How can you pass bindings to component/directive without this controller in modal open action ? |
@Olgagr the controller should be defined on your component, so it'd receive its bindings through the bindings object, just as in the case of ui-router. |
Let's make sure to get this right. I think for @Olgagr's use case, how we want to do this should be
where I think this makes the most sense since all that controller stuff isn't needed here since that should be encapsulated by the component. This may require a bit of extra verbosity in some cases due to having to define the component, but it isn't necessary to change to this syntax - this is just offering a different option for those who desire it. It is wholly backwards compatible with pre-Angular 1.5 because it doesn't rely on anything Angular 1.5 specific in the library itself, and provides simplicity in API form. Thoughts? |
I might be getting that wrong way, but the end result would mean, that when I instantiate modal open action I pass in a resolve object containing the elements, that will be injected into component responsible for modalInstance, correct? If so, then how will resolve object be injected into component? Like before as for responsible controller, where every resolve property was a function and result was independent injectable for that exact responsible controller or in some other way? Maybe a more complete example could be provided for the vision? |
@jeserkin in the example of the proposal I posted, the modal would create <different-component $resolve="$resolve"></different-component> and one would be responsible for determining how the resolve is handled inside the component. |
@wesleycho your example is exactly how I'd envision using this. Resolve's should automatically map to the component's bindings when provided, eliminating the need for a wrapping controller or template. |
I have opened an implementation in #6179 - if there is any comment about implementation anyone wants to add, feel free to comment in that PR. |
Awesome!, I was just searching for this possibility 👍 Many thanks |
Hello,
I want to ask if you're considering support of
angular.component
method which is new API for creating components.I'd like to have the ability to call
$modal.open
method with the component definition. Now I have to specifycontroller
andtemplate
options...My API proposal:
Thanks for response.
O.
The text was updated successfully, but these errors were encountered: