Demo > Dynamic Update

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.


Update input-model

Click one of the buttons below to load different data into it.

Update singular data

You can also update a single item. Operations like these are totally valid:

For example, click this button below to change the name of the first chosen browser, into 'Hello World'.


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:

$scope.modernBrowsers = [
  { icon: "{{removeHost(row.icon)}}", name: "{{row.name}}", maker: "{{row.maker}}", ticked: {{row.ticked}} },
];
$scope.oldBrowsers = [
  { 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' );
Output model

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.

$scope.outputBrowsers = [
  { icon: "{{removeHost(row.icon)}}", name: "{{row.name}}", maker: "{{row.maker}}", ticked: {{row.ticked}} },
];
Learn more

Open the /docs/js/controllers/demo-dynamic-update.js, as well as this view docs/views/demo-dynamic-update.htmto learn the code directly.