How to add an angularui accordion-group dynamically - angularjs

In an angularjs service, I am adding the HTML for an accordion-group to the DOM of an accordion element. What results is the display of the accordion-group as if it were a panel - no title bar, no collapse behavior.
I'm sure it is because the accordion gets initialized before the content is added. The jQueryUI accordion has a refresh method for such occasions, but not sure how to get the angualrui accordion to recognize the new accordion group.

hope the following steps help :
get the reference of the element where you want to add the accordion
HTML : <div id = "myAccordion"> </div>
Controller : var parent = angular.element("#myAccordion");
Compile your accordion template and attach it to the parent
Controller: var accordion = $compile("<div accordion> </div>")($scope);
parent.append(accordion);
but this is a work around you should ideally have a directive to do DOM manipulation , perhaps you are coding with jquery in mind.

Related

in angular UI collapse ,Initial page load showing div as collapsed

I am trying to use a collapse model in angular UI
<div class="" ng-click="isCollapsed =!isCollapsed" ></div>
and in my controller i set the value
$scope.isCollapsed = true;
but my initial pageload shows the div as collapsed. I want to hide it initially .Could someone help me with this

Rending a Modal in AngularJS

I'm attempting to learn AngularJS (background in BackboneJS). I have a div with some content inside, and I hope to render this div as a modal upon clicking inside of it:
<div class="stickynote"> Content here </div>
My thinking is to add a modal class that I can style in CSS. However, I'm not too sure how to add the modal class upon clicking (and conversely, removing the modal class upon clicking after the modal is rendered). Would I have to use ng-click and somehow set the class property from the JavaScript (myApp.js) file?
If you want to use your own modal styling and if you simply want to achieve adding an extra item to class attribute of your element, you can use a combination of ng-class and ng-click:
<div class="stickynote"
ng-class="{yourModalCSSClass: isModalOpen}"
ng-click="isModalOpen = true">
And somewhere else, you need another ng-click to turn it off:
<button ng-click="isModalOpen = false">Close modal</button>
Beware that both div and button must be in the same scope hierarchy to be able to use the same isModalOpen value. And by the way, I haven't tried this code but this should give you an idea. If you have a controller/directive, you can set isModalOpen from there by introducing functions in the scope:
// controller
$scope.toggleModal = function () {
$scope.isModalOpen = !$scope.isModalOpen;
}
<div ...
ng-click="toggleModal()">
<button ng-click="toggleModal()">...
If you're open to using a third-party solution, ng-dialog is an outstanding solution for modals+Angular.
https://github.com/likeastore/ngDialog

Angular bootstrap lazy loaded tabs , autoselecting the tabs

I am using tabs of angular bootstrap ui. I have overriden the tabs directive so as to perform lazy loading of data
Plunkr link for the same : http://plnkr.co/edit/uAb3TrKtxoPPXx8mekRz?p=preview
The lazy loading works perfectly fine. However I need to dynamically select the tabs based on certain properties.
For example, I tried the following
<div class="row" ng-controller="TabCtrl">
<tabset>
<tab title="Tab 1" template-url="tab1.html" active="{{tab1stat}}"></tab>
<tab title="Tab 2" template-url="tab2.html" active="{{tab2stat}}"></tab>
</tabset>
</div>
and in my controller.js I tried setting the active property for the tabs in the scope
app.controller('TabCtrl', ['$scope',
function($scope) {
// $dialogs.error('t est');
$scope.tab1stat=false;
$scope.tab2stat=true
}
]);
I tried accessing the scope variables in the html, however the tab directive seems to get rendered before the controller is initialized.
Is there any way to achieve this?
Also I need to refresh the tab with a different html. For example my tab1.html will have a few buttons which will render some html pages. All these pages need to be rendered in the same tab.Is there any way to achieve this?
Try removing the curly braces from the active attribute binding so it looks like so: active="tab2stat". You should also not be binding to primitives to avoid the prototypal inheritance gotcha.
EDIT
The angular ui bootstrap library is watching the active attribute like so:
scope.$parent.$watch($parse(attrs.active), function (value) {
alert(value);
});
See this plunkr: http://plnkr.co/edit/pwXOz1O4Wb0RZsi3nPlC?p=preview

make div fullscreen on click using angular js only

I just need to make a div fullscreen whenever a user clicks on that div. I know this can be done via javascript and jquery. But i want to know if there is any pure angular js method of doing it. Any suggestions in this regard would be appreciated
You can use a fullscreen directive like this ones:
https://github.com/hrajchert/angular-screenfull
https://github.com/fabiobiondi/angular-fullscreen
One way is to use ngClass to apply a fullscreen class based on a boolean scope property. And use ngClick to toggle the scope property when clicked...
<div ng-click="isFullScreen = !isFullScreen"
ng-class="{fullscreen: isFullScreen}">click me</div>
Fiddle
Making a div fullscreen is(should be) about css, so you can change your div's css class via angular like:
html
<div ng-class="{fullScreenDiv: isFullScreen}">...</div>
<div ng-click="makeFullScreen()"></div>
js
$scope.isFullScreen = false;
$scope.makeFullScreen = function(){
$scope.isFullScreen = true;
};
fullScreenDiv is css class and isFullScreen is a variable in your controller scope. Change isFullScreen variable to enable/disable full screen.
Meaining of ng-class="{fullScreenDiv: isFullScreen}" is if isFullScreen expression evaluates to true then apply fullScreenDiv css class to element.

How to get AngularStrap active tab?

I am somewhat new to using Angular and AngularStrap directives. I need to use the tab directive with static markup like the example:
<div data-fade="1" bs-tabs>
<div data-title="'Home'"><p>Static tab content A</p></div>
<div data-title="'Profile'"><p>Static tab content B</p></div>
</div>
On another part of the page I would like to display a div only when the first tab is selected. The div is not part of the tabs, but is in the same overall controller. How can I show/hide this div based on the selected tab?
Something like this?
<div ng-show="???? active tab stuff here ????">Home tab is selected</div>
Thanks for any help.
As shown in the example on the AngularStrap page the active tap is stored in
tabs.activeTab
So you can use this property to conditionally show display something else like so
<div ng-show="tabs.activeTab == 0">The first tab is active</div>
UPDATE
Even with non object tabs you can just bind a model against the bs-tabs to store the active ID like so:
<div data-fade="1" ng-model="tabs.activeTab" bs-tabs>
Here is an updated plnkr. (Click on the 3rd tab and see the 'Test' text appear)
I found somewhat of a hack to resolve this issue for now. This does not seem like the best approach, so if someone has a better idea, please share.
I realized that the bsTabs directive is creating data-toggle attributes for each tab. By watching the data-toggle shown event, I am able to recognize the tab change and display the div. The controller code looks like this:
$scope.HomeTabSelected = true;
function watchTab() {
$('a[data-toggle="tab"]').on('shown', function (e) {
$scope.$apply($scope.HomeTabSelected = (e.target.innerHTML == "Home"));
})
}
setTimeout(watchTab, 2000); // setTimeout necessary to allow directive to render
and the HTML div uses ng-show.
<div ng-show="HomeTabSelected">Home tab is selected</div>

Resources