I am new to angular, trying to figure out how the bootstrap alert work in angular
in regular bootstrap something below gives the alert message and it gets closed when clicked on X
<div class="alert alert-success">
×
<strong>Well Done!</strong> Your action is successful.
</div>
All the examples i saw are using AlertCtrl and needed to code the array of alerts and need to code a method to splice the array when close button clicked.
In a Single Page Application, If i want to show only one success alert message when user perform an action
.directive('myCustomAlert', function(){
return {
restrict:'E',
template:'<alert type="success" close="close">{{model-dynamic-msg}}</alert>',
controller:'MyCtrl'
}
since the close attribute present the alert is displaying well. when added
<my-custom-alert></my-custom-alert>
but not able to dismiss the message when clicked on x
here is the plunker : http://plnkr.co/edit/NfEleLc0Q6pzjirb3DCg
am i missing to include any library.
add this on you include script tags:
<script src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.10.0/ui-bootstrap.min.js"</script>
UPDATED:
Like what #Sunil D. mentioned. You don't have to create your own bootstrap alert directive if you are using UI-Bootstrap, it is the purpose of the ui-project. If you look on ui-bootstrap docs about alert, you can see they are using ng-repeat to render alerts and handle remove alerts by just removing the index of the generated alert.
it can be as simple as this, without directive or controller:
<alert type="danger" close="bCloseAlert=1" ng-hide="bCloseAlert">i'm alert</alert>
Related
I am a rookie in AngularJS. I am building a corporate dashboard. I have two views - Dashboard and Profiles. In Profiles I have multiple profile details which I am rendering using ng-repeat and the JSON is also present inside the profiles controller. Whenever a user clicks on one of the profile I want to redirect it to that profile's dashboard.
Now, inside the ng-repeat:
<md-card ng-repeat="data in epc.employees" class="empCard md-whiteframe-4dp" >
I am using ng-click like this:
<a ui-sref="dashboard"><md-button ng-click="loadGraphs({{data.id}})">View Dashboard</md-button></a>
The loadGraphs function is defined independently in another JS sheet and is used to manipulate the C3.js Charts. Now, whenever I click on the button I get redirected to dashboard with the following error:
angular.js:10347 Error: [$parse:syntax] Syntax Error: Token '{' invalid key at column 8 of the expression [check({{data.id}})] starting at [{data.id}})].
I have also tried:
<a ui-sref="dashboard"><md-button ng-click="loadGraphs(data.id)">View Dashboard</md-button></a>
In this case there is no error but the function is not being called while redirecting to dashboard.
Please help.
Actually in ng-click you dont need to use brackets:
<md-button ng-click="loadGraphs(data.id)">View Dashboard</md-button>
If you still get error, check if there is no typo in your function names and if you are using the same scopes (controllers). I recomend you checking some angular tutorials.
I'm new on Angular JS + Bootstrap 3 and I'm trying to do something for maps. the thing is that I need to open a modal, and then from a button of that modal open another modal.
This is the external html:
<div class="modal-header">
<h1>Editor<h1>
</div>
<div class="modal-body" >
<button class="btn btn-primary" ng-click="treureModalEdit()" data-dismiss="modal">Afegir Punt</button>
</div>`
Here is my example: http://plnkr.co/edit/Zx68EQ?p=info
If something does not load is because libraries, but i only need help where the button 'Posa Marcador!' is.
Some code is in catalan, sorry if that discourages you to help me.
Thank you!
If you inspect with your browser's developer tools the first modal that you open you will see that the markup for this modal is appended to the end of your HTML body, which means that the modal is not nested in your <div ng-controller="DialogDemoCtrl">. This in turn means that the modal does not have a controller of its own, and therefore cannot "understand" the ng-click="treureModalEdit()" you have defined for your button.
In order to fix this problem you should create a second controller and use it for your modal. The treureModalEdit() would then be placed into that second controller.
A few other comments I have on your code:
You use things like data-toggle="modal" data-target="#modalEdit", however this is how you would be opening your modal if you did not have an Angular application. In your Angular application what you actually use is the ng-click="func()" you have put on the button. You can therefore clean all this dead code from your HTML (data attributes and modal template).
If you are new to Angular I would suggest using a newer version in order to avoid any problems which might be fixed in newer versions. You can use the latest version (1.4.0) or a 1.2.x version is you need to support IE8 (which is not officially supported since Angular version 1.3.x.
I have a product page, and there is an option for a 'quick view' which opens the product description and images in a modal. I also have a 'full details' button where I would like the user to be taken to a new URL based on the item code, but also display the information from my JSON for that clicked product. This is what I have:
<a ng-click="store.selected = product" ng-href="{{store.selected.code}}.html" class="btn btn-sm">Full details</a>
Everything works great for the Modal, so I am presuming there is a problem moving onto a different page and carrying this information across? I have mocked it up in Plunker to show the problem:
Plunker here
Any help would be much appreciated.
You should consider using ng-route to switch the view to a different html file. But you can also use ng-include with a little less set up.
When the Full details link is clicked, toggle a variable that tracks whether the gallery or the details should be visible. And, construct the path to the html template you want to display:
$scope.setSelection = function(product) {
$scope.store.selected = product;
$scope.detail.show = !$scope.detail.show;
$scope.detail.source = product.code + '.html'
}
Then, use ng-include to display the template:
<div ng-if="detail.show" ng-include="detail.source">
</div>
Here is an update of your plunker: http://plnkr.co/edit/zhsY6TAjONewyInGiwUC?p=preview
Note that the template should just be a snippet of html.. you don't need to include scripts like angular again.
I am facing a strange behavior when testing an Angular JS application with protractor.
Considering this HTML structure , I would like to click on the inner div which is a filter.
<div ng-hide="term.selected" ng-click="selectFilter('target',term.value)" class="listItem">
<div>
<label class="ng-binding">ZECPFICO00</label>
<span class="listItemNum ng-binding">157</span>
</div>
</div>
Here is my locator :
element(by.repeater('term in facets.target | filter:ecSearchText').row(1)).click ();
When executing this code my webdriver cursor goes to the filter in the web page but and tries to click on the filter however the click does not work and therefore the filter is not applied.
1 - You don't need to specify the filters when using by.repeater it is optional
2 - Sirk is almost there, you need to continue chaining your promises, below an example of clicking on a div, you can use any by method here..
var elements = element.all(by.repeater('term in facets.target'));
elements.first().then(function (term) {
term.findElement(by.css('div')).then(function (div) {
div.click();
});
});
3- You could also do it this way:
element.all(by.repeater('term in facets.target')).get(0).click();
hmm I've never seen or used a locator that way where you have .row(1), but I am a noob so that just might be my own ignorance, however you could try something like the following:
element(by.repeater('term in facets.target | filter:ecSearchText')).then(function(rows){
rows[0].click();
});
That should click on the first row of the repeater. 'rows' would contain all the rows as an array.
I have the following code:
<form class="form"
data-ng-submit="modalSubmit(modal.data)"
id="modal-body"
name="modalForm"
novalidate>
This works and when I click on a button of type submit then the modalSubmit function is called.
However I would like to do this in my controller:
$scope.modalForm.$setPristine();
But it gives an error saying:
has no method '$setPristine'
How I can I set the form to pristine? I did try adding data-ng-form="modalForm" but then I get
a message saying something to the effect of duplicate directive names.
I tried changing the form element to a DIV but then the clicking on the submit button does not call
the function
Here's an example (modified from another user) that shows what I am trying to do which is set values to pristine:
plnkr.co/edit/LNanJdAggMLIgxii0cfv?p=preview
You're not doing anything wrong there, only problem is you're referencing an old version of angular in which $setPristine() was not a feature. $setPristine() was added in 1.1.+, so reference a newer version of angular and you're good to go. See it working in this plunk, using 1.2.+.
If you can't upgrade, then a dirty workaround would be to loop through all inputs in the form and set their $dirty and $pristine values manually:
$scope.mp = function() {
$scope.mainForm.$pristine=true;//clean main form
$scope.mainForm.$dirty=false;
angular.forEach($scope.mainForm,function(input){//clean all input controls
if (input !== undefined && input.$dirty !== undefined) {
input.$dirty=false;
input.$pristine=true;
}
});
}
First, your version of angular was old, 1.2.12 is the latest stable on the CDN. But even it wouldn't allow $setPristine because of the HTML5 validation that was going on.
The biggest problem was you used required on the fields instead of ng-required. The browser was doing the form validation for you instead of angular. You could also add the novalidate attribute to the form tag.
http://plnkr.co/edit/l1mUCceSFMFFZWgGgL6u?p=preview
it has already been implemented in this link you can use it this was as it has been demonstrated in the plnkr link.
As you can see from the above description, $setPristine only changes the state of the form (and thereby resets the css applied to each control in the form).
If you want to clear the values of each control, then you need to do for each in code.