I'm learning AngularJS and I'm having some difficulties with dialogs.
Since i'm converting my app from a classical Jquery-based to an angular one, i want to use Fancybox to open dialogs with custom dynamic HTML inside, with the fancybox open method.
$.fancybox.open(html);
I wrote a service to use fancybox: now i open my dialogs but the content inside the dialog is not "compiled" against angular, so any angular directive set on that HTML doesn't work.
See the example
http://plnkr.co/edit/UwryF1ocleyND7zxCGJz?p=preview
I imagine that the problem is in the service, but i don't know how to fix it. Could you show me how i can get an html sensible to angular directive inside the HTML shown in the dialog?
UPDATE:
i've tried to use $compile, and set a directive instead of a service (calling the method inside the directive directly from ng-click)
http://plnkr.co/edit/Y18bRSMdV62VObMGJ2Ie?p=preview
what's wrong now? why my $compile doesn't work as expected?
The problem is that angular looks for function expressions only on the scope and NOT on window as plain-javascript does. Hence, when you add an alert function on the $scope, it will be wired correctly: http://plnkr.co/edit/y02UMQ2kU4fh8Imsa82u?p=preview
$scope.alert = function (phone) { window.alert(phone.name); };
Related
Using angular-ui popover you can put an html inside a popover. If for example I have a directive named sampleDirective (assuming this directive exists) how can I put it inside the popover? I tried using $sce.trustAsHtml but it doesn't work. I also tried $compile but failed miserably.
$sce.trustAsHtml('<sample-directive></sample-directive>');
Is there a way to use to put an element directive inside a popover?
As said by Alon Eitan, instead of using ui-popover-html, I used ui-popover-template instead and directed the templateUrl of the directive to it.. In this case, there is no need of an isolated scope anymore..
I'm new in AngularJs. I try to make web with AngularJs and Bootstrap. when I call bootstrap modal I use this script :
$scope.here = function here(f) {
$('#smallModal').modal();
$('#contentin').html(f);
}
that code I call use ng-click=here('test')
in my header html i still use Jquery library. My question is , is it posiblle to unload jquery for call modal bootstrap who called with $ prefix. I don't want to use any plugin except AngularJs
If you want to make use of Bootstrap's modal, one option is to use Angular-UI's Bootstrap (if that isn't what you're already using), which puts Bootstrap components into Angular directives for you. Specifically, you would inject the $modal service into whatever module needs to control the modal. Here's an example of how to use the $modal service.
There are many ways of displaying model dialog out there. You can easily search with google.
btw, AngularJS use jQuery - or jQuery lite in the backend.
I'm currently using Angular and Require in a project for the first time. At the moment it seems like it's very hard to do the things that should be simple when using Angular.
I'm currently trying to put a click event using jQuery for a simple tabbed menu and of course, $(document).ready will not work because Angular loads the views after this has fired. Are there any examples of how to implement jQuery plugins with Angular (and Require)?
Also, I will need to turn jQuery plugins on/off on window resize using another plugin. What is the correct method of doing these things? Any help would be greatly appreciated.
I've attached some (very) stripped down code from a controller. I have also tried putting the click event straight between the angular.element ready code. Still doesn't seem to work.
define(['app', 'modules/Social'], function(app, social) {
'use strict';
return app.controller('HomeCtrl', function($scope, $http) {
angular.element(document).ready(function () {
// This code attaches an event listener in jQuery (.click())
social.init();
});
});
});
EDIT: I am using includes as templating and it appears that the includes are getting fired AFTER the angular.element ready function. Which means it is not adding the event listener.
The Code
You can find the JSFiddle in question at: http://jsfiddle.net/SeanKilleen/A3QtJ/
Background / What I'm Trying to Accomplish
I'd like a Feedback button to place on our web site, likely in the Site.Master file (it's an asp.net web site)
When the feedback link is clicked, I'd like to show a modal dialog
I'd like to bind the link and the elements inside of the modal to a specific knockout viewmodel
I'd like to properly namespace it so that it doesn't interfere with any other scripts that might come up on other pages
I'd like to apply the Knockout bindings only to this portion of the code, because other subsequent pages, etc. might also have bindings.
To do this, I have the following main toolset: Knockout, jQuery, and jQueryUI (jQueryUI isn't my particular choice but that ship has sailed).
The Problem
In the JSFiddle link, the following code currently works:
$(document).ready(function () {
vm = new FeedbackNamespace.ViewModel();
ko.applyBindings(vm);
});
However, when I change ko.applyBindings(vm) to:
ko.applyBindings(vm, document.getElementById('FeedbackArea'));
The link part of the binding (that is mound to a viewmodel function to show the dialog) still works. However, none of the bindings inside the modal dialog still work.
Question(s)
How can I properly apply the viewModel to only a section of the site in this case?
Is this method of doing things still going to cause problems with child pages that might load their own knockout viewmodels and apply them?
Are there other examples of this sort of thing being done? I've been looking but unable to find them.
Thanks in advance for any help you can give!
The problem is here:
self.Start();
this sets up the modal, removing it from the FeedbackArea div. This happens in the process of creating the viewmodel, such that when this newly created vm is actually applied to the div a moment later, that modal is now gone, which is why nothing inside of it responds like it does when you apply the VM to the entire page.
I would make sure that Start method is called AFTER you apply bindings.
LIKE THIS
I am new to AngularJs and I got stuck with a situation where I need your help.
I am loading content using $http service within an angularjs controller and on loading the content I am replacing the new content (with the new controller) from Ajax with the whole currently working controller and I am doing this replacing part using jQuery .html() function. Now the issue is that the content loaded perfectly but the functionality of new controller is not working at all.
As I told that I am new here, please guide me if I am following right technique and what would be the solution to this problem or is there any new option to do task.
I also tried loading the content with directive but after using it, the loaded content won't perform any functionality at all.
you need to compile the new content (with new controller) before replacing it. you can use $compile service for that.
This works for me.
angular.bootstrap($('body'), ['app']);