There seems to be a problem converting ui.bootstrap.buttons to be used with ng-repeat. The ui.bootstrap.buttons example and documentation is here: http://angular-ui.github.io/bootstrap/
Bascially the default example works nicely: http://plnkr.co/edit/2O81y57GtfP6EPNH9qYa?p=preview
<div class="btn-group">
<label class="btn btn-primary" ng-model="radioModel" btn-radio="'Left'">Left</label>
<label class="btn btn-primary" ng-model="radioModel" btn-radio="'Middle'">Middle</label>
<label class="btn btn-primary" ng-model="radioModel" btn-radio="'Right'">Right</label>
</div>
But when it's converted the use ng-repeat, it breaks: http://plnkr.co/edit/nzx1VTGN4Q59JlFCU53V?p=preview
<div class="btn-group">
<label ng-repeat="test in ['Left', 'Middle', 'Right']" class="btn btn-primary" ng-model="radioModel" btn-radio="'{{test}}'">{{test}}</label>
</div>
Try
<label ng-repeat="test in ['Left', 'Middle', 'Right']" btn-radio="test" class="btn btn-primary" ng-model="radio.model">
instead of
btn-radio="'{{test}}'"
On top of this ng-repeat is creating a new scope so you need to account for this as well. Here is a working plunk: http://plnkr.co/edit/h5e5OgFCqv28MPy4tEaM?p=preview
In the end after some testing I got it working using ng-class for initial selected value and own ng-click handler that changes the selected button
HTML-code for the buttons:
<div class="btn-group">
<button ng-repeat="(timelineIndex, timeline) in timelines" ng-click="selectTimeline(timeline)" ng-class="{active: timeline.name === selectedTimeline.name}" class="btn btn-primary">
{{timeline.name}}
</button>
</div>
in controller:
$scope.selectTimeline = function(activeTimeline) {
$scope.selectedTimeline = activeTimeline;
};
Related
Please, someone there some idea why angular ui-bootstrap popover is not changing the model in scope?
<button popover-placement="right"
uib-popover-template="'myPopoverTemplate.html'"
type="button"
class="btn btn-default">Click me!</button>
....
<script type="text/ng-template" id="myPopoverTemplate.html">
<div class="form-group">
<label>Date:</label>
<p class="input-group">
<input type="text"
class="form-control"
ng-model="dataClonada"
datepicker-options="dateOptionsClone"
uib-datepicker-popup="{{formats[5]}}"
is-open="popup3"
readonly="true"/>
<span class="input-group-btn">
<button type="button" class="btn btn-default" ng-click="popup3=true"><i class="glyphicon glyphicon-calendar"></i></button>
</span>
</p>
<button class="btn btn-success" ng-click="show()">show value</button>
</div>
</script>
I did one simple plunker to show the situation.
https://plnkr.co/edit/ebYWI8hP0xtOboY2v37Z?p=preview
You need to change
ng-model="dataClonada"
to
ng-model="$parent.variable"
The directive (apparently) is creating a new child scope, so you need to use $parent to access the parent scope and access it's values (where variable resides).
Fixed plnkr
For some reason for me it worked with double parent:
ng-model="$parent.$parent.variable"
Can be, because the popover was inside of a repeater?
Acutally I am learning angularjs. I've introduced a problem is that when I click ng-click, ng-model is not updating. My code is as follows,
<div ng-repeat="product in cart">
<input type="number" ng-model="product.quantity" ng-required class="input-sm">
<button class="btn btn-xs" type="button" ng-click="product.quantity++">+</button>
<button class="btn btn-xs" type="button" ng-click="product.quantity--">-</button>
</div>
try like this
<button type="button" ng-click="product.quantity = product.quantity+1">+</button>
<button type="button" ng-click="product.quantity = product.quantity -1">-</button>
Try This
var jimApp = angular.module("mainApp", []);
jimApp.controller('mainCtrl', function($scope){
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="mainApp">
<div ng-controller="mainCtrl">
<input type="number" ng-model="product.quantity" ng-required class="input-sm">
<button class="btn btn-xs" type="button" ng-click="product.quantity = (product.quantity +1)">+</button>
<button class="btn btn-xs" type="button" ng-click="product.quantity = (product.quantity -1)">-</button>
</div>
</div>
I open a popup using ngDialog.Now i want to expand textboxes more .but the popup is expanding according to textboxes.But i need only a div part to be scrolled on the popup in which in div we are expanding textboxes.Is it possible.if possible can anyone help me to solve.
//js file
$scope.radiolabels=[];
$scope.addradio=function(){
ngDialog.open({
template:"popupfiles/radioname.html",
closeByDocument:false,
closeByEscape:false,
scope: $scope,
showClose:false
});
};
$scope.expndradiolabels=function(){
$scope.order++;
var objt={
Name:"",
type:"radiobtns",
rbtn:[{
Name:"",
order:$scope.order
}]
};
$scope.radiolabels.push(objt);
};
$scope.cancelradioname=function(){
ngDialog.closeAll();
};
//html file
<h3 style="color: #0d7dc1;margin-top: 0px;">Enter the Heading name for RadioButtons</h3>
<h3>Headings For RadioButons:</h3>
<div style="overflow:auto;">
<ul>
<li ng-repeat="radiolbs in radiolabels track by $index">
Label: <input type="text" id="ral_{{$index}}" data-ng-model="$parent.radiolabels[$index].Name"/><br>
RadioButtons {{$index}}: <input type="text" id="rab_{{$index}}"><br>
RadioButtons {{$index}}:<input type="text" id="rab_{{$index}}"><button class="btn btn-default">+</button>
<li>
<button class="btn btn-default" ng-click="expndradiolabels()">Click to add multiple radio headings</button>
</li>
</ul>
</div>
<button type="submit" class="btn btn-default pull-right" ng-click="saveradioname()">Save</button>
<button class="btn btn-default" ng-click="cancelradioname()">Cancel</button>
I'm trying to add angular-bootstrap tooltip in each button of button-group. When I do this, hovering right button destroys all buttons styles.
html:
<div class="btn-group" style="margin-top:100px;">
<label class="btn btn-primary" tooltip="{{dynamicTooltip}}" ng-model="radioModel" btn-radio="'Left'">Left</label>
<label class="btn btn-primary" tooltip="{{dynamicTooltip}}" ng-model="radioModel" btn-radio="'Middle'">Middle</label>
<label class="btn btn-primary" tooltip="{{dynamicTooltip}}" ng-model="radioModel" btn-radio="'Right'">Right</label>
</div>
js:
angular.module('ui.bootstrap.demo', ['ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('TooltipDemoCtrl', function ($scope) {
$scope.dynamicTooltip = 'Hello, World!';
});
Here is my plunker: http://plnkr.co/edit/NFjJJXEKyJHDgddcPdNa?p=preview
It's because your tooltip is generating inside the btn-group. This means the 'Right' button is no longer the last element in the group, as such the styling changes until the tooltip disappears. Try appending the tooltip to the body, rather than the parent.
<label class="btn btn-primary" tooltip="{{dynamicTooltip}}" tooltip-append-to-body="true" ng-model="radioModel" btn-radio="'Right'">Right</label>
Consider a form with three buttons:
<form ng-submit="updateUser()">
<div>Name <input type="text" ng-model="userToEdit.name" /></div>
<div>
<button class="btn btn-primary" ng-click="updateUser()">Save</button>
<button class="btn" ng-click="cancelEdit()">Cancel</button>
<button class="btn btn-danger" ng-click="deleteUser(userToEdit)"><i class="icon-trash"></i> Delete</button>
</div>
</form>
When I click cancel, cancelEdit() is being called, then updateUser() is being called. I don't want the updateUser() method to be called. Is there a way to suppress this form submission (preferebly wtihout jQuery?)
Note: I'd still like to be able to hit enter and default to the Save action.
There is a type attribute for the <button> which defaults to submit - see this spec. Thus every button in your form is a submit button. You need to specify the button type for buttons which should not trigger the form submission, like this:
<form ng-submit="updateUser()">
<div>Name <input type="text" ng-model="userToEdit.name" /></div>
<div>
<button class="btn btn-primary">Save</button>
<button type="button" class="btn" ng-click="cancelEdit()">Cancel</button>
<button type="button" class="btn btn-danger" ng-click="deleteUser(userToEdit)"><i class="icon-trash"></i> Delete</button>
</div>
</form>
And also no need to put the submit action to both ng-click and ng-submit - it will trigger double submit. I would advise to use ng-submit because it catches all ways of form submission, like pressing ENTER and not only clicking on submit button.
Try this
<form ng-submit="updateUser()">
<div>Name <input type="text" ng-model="userToEdit.name" /></div>
<div>
<button class="btn btn-primary">Save</button>
<a class="btn" ng-click="cancelEdit()">Cancel</a>
<a class="btn btn-danger" ng-click="deleteUser(userToEdit)"><i class="icon-trash"></i> Delete</a>
</div>
</form>
or this
<form>
<div>Name <input type="text" ng-model="userToEdit.name" /></div>
<div>
<button class="btn btn-primary" ng-click="updateUser()">Save</button>
<button class="btn" ng-click="cancelEdit()">Cancel</button>
<button class="btn btn-danger" ng-click="deleteUser(userToEdit)"><i class="icon-trash"></i> Delete</button>
</div>
</form>
ultimately I don't think you need updateUser() twice in the html
You can use for cancel button type="reset":
<button type="reset" class="btn" ng-click="cancelEdit()">Cancel</button>
The button is a reset button (resets the form-data to its initial values)
http://www.w3schools.com/tags/att_button_type.asp
I was having same problem.I used anchor instead of button.
<form ng-submit="updateUser()">
<div>Name <input type="text" ng-model="userToEdit.name" /></div>
<div>
<button class="btn btn-primary" ng-click="updateUser()">Save</button>
<a class="btn btn-danger" ng-click="cancelEdit()" role="button">Cancel</a>
<button class="btn btn-primary" ng-click="deleteUser(userToEdit)"><i class="icon-trash"></i> Delete</button>
</div>
</form>