Using AngularJS, select ng-options with a semantic interface dropdown

Thus, the semantic user interface appears in the last “hot” user interface structure that I am impressed with; however, their drop-down menu is not an implementation of the HTML "select" and "option" tags, but instead a normal one. For my project, I use AngularJS, which is the phenomenal base of JavaScript MVW.

How can I integrate AngularJS to select ng-option with a semantic interface drop-down list ? I am not a professional JS. Here's JSfidde: http://jsfiddle.net/fMUy3/

    <!doctype html>
<html ng-app="App">

    <body ng-controller="MainCtrl">
            <h3>Option 1 (standard)</h3>

        <select ng-model="selectedItem" ng-options="c as (c.id + ' - ' + c.name) for c in containers">
            <option value="">-- Pick A Container --</option>
        </select>
        <br>ID: {{selectedItem.id}}
        <br>Name: {{selectedItem.name}}
         <h3><a href="http://semantic-ui.com/modules/dropdown.html"> Semantic UI Dropdown</a></h3>

        <div class="ui selection dropdown ">
            <input name="id" type="hidden" value="0">
            <div class="text">-- Pick A Container --</div>  <i class="dropdown icon"></i>   
            <div class="menu transition hidden">
                <div class="item active">-- Pick A Container --</div>
                <div data-value="{{container.id}}" class="item" ng-repeat="container in containers">{{container.name}}</div>
            </div>
    </body>

</html>

JavaScript:

var app = angular.module('App', []);

app.controller('MainCtrl', function($scope) {
  $scope.containers = [
  {id: 1, name: 'Box1'},
  {id: 2, name: 'Box2'},
  {id: 3, name: 'Box3'}];

  //$scope.selectedItem = $scope.containers[0];
});

$('.ui.dropdown').dropdown();

Very valuable!

+4
2

: semantic.js jquery.

-, ng-options div, ng-click

HTML

 <div data-value="{{container.id}}" class="item" ng-repeat="container in containers" ng-click="select(container)">
     {{container.name}}
 </div>

JS

$scope.select = function(container) {
    $scope.selectedItem = container;        
};

.

+1

. -, JavaScript- jQuery. jQuery, jQuery. ( , jQuery AngularJS.)

-, , AngularJS , . , , . -, ; , AngularJS . ,

.
http://jsfiddle.net/fMUy3/1/

$timeout(function(){
    $('.ui.dropdown').dropdown();
},0)

- , , . ( )

http://jsfiddle.net/fMUy3/7/

app.directive('dropdown', function ($timeout) {
    return {
        restrict: "C",
        link: function (scope, elm, attr) {
            $timeout(function () {
                $(elm).dropdown().dropdown('setting', {
                    onChange: function (value) {
                        scope.$parent[attr.ngModel] = value;
                        scope.$parent.$apply();
                    }
                });
            }, 0);
        }
    };
});
+7

All Articles