The directive listens to changes on their input $scope
variable.
This is how you programatically update the directive - by changing the input model - and it will
refresh accordingly.
Click one of the buttons below to load different data into it.
You can also update a single item. Operations like these are totally valid:
$scope.modernBrowsers[ 1 ].ticked = false
, or$scope.modernBrowsers[ 1 ].name = 'Hola!'
Define your directive:
<div
isteven-multi-select
input-model="dynamicData"
output-model="outputBrowsers"
button-label="icon name"
item-label="icon name maker"
tick-property="ticked"
>
</div>
...
<!-- The buttons to do data operation -->
<button type="button" class="btn btn-success btn-xs" ng-click="switchSource( 'modernBrowsers' )" >Load modern browsers</button>
<button type="button" class="btn btn-primary btn-xs" ng-click="switchSource( 'oldBrowsers' )" >Load old browsers</button>
<button type="button" class="btn btn-warning btn-xs" ng-click="dynamicData[ 0 ].name = 'Hello World!'" >Update singular data</button>
Define your input-model:
{ | icon: "{{removeHost(row.icon)}}", | name: "{{row.name}}", | maker: "{{row.maker}}", | ticked: {{row.ticked}} | }, |
{ | icon: "{{removeHost(row.icon)}}", | name: "{{row.name}}", | maker: "{{row.maker}}", | ticked: {{row.ticked}} | }, |
Some extra codes here; $scope.swithcSource()
is a function where we switch
the $scope.dynamicData
content with modern or old browsers.
// This will be our input model
$scope.dynamicData = [];
// Just a function to switch the model on button click.
$scope.switchSource = function( data ) {
$scope.dynamicData = angular.copy( $scope[ data ] );
}
// Initially we'll use the modern browsers
$scope.switchSource( 'modernBrowsers' );
Look at the output-model
below to see the values getting updated
as you select / deselect an item in the directive. Icons in the objects are actually full HTML img
tag, shortened for simplicity.
{ | icon: "{{removeHost(row.icon)}}", | name: "{{row.name}}", | maker: "{{row.maker}}", | ticked: {{row.ticked}} | }, |
/docs/js/controllers/demo-dynamic-update.js
, as well as this view
docs/views/demo-dynamic-update.htm
to learn the code directly.