Angularjs: Associate complex objects with selectbox without ng-options

I need to link complex objects using a select box.

I know ng-options , but I cannot use the template expression in ng options. I would need to add a field with displaytext for each object in my controller, as in this fiddle . This would mean that I would need to change the logic / code for the presentation. This is a poor separation of concerns.

Is it possible to associate complex objects with a selection field not using ng-options? I need to write declarative text in a template, for example:

<select name="myObject" ng-model="myObject.sub">
    <option ng-selected="!myObject.sub.id"></option>
    <option value="" translate="myObject.sub.self" ng-selected="myObject.sub.id == -1">
    <option ng-repeat="option in subselect.data" value="{{option}}" ng-selected="option.id == myObject.sub.id">
        {{option.id}} {{option.shortName}} {{ option.comment }}
    </option>
</select>

this currently binds the string [object Object]due to interpolation in the value attribute.

+4
1

ng-change, , .

HTML

<label ng-controller="CompanyController" for="ci-company_sid">
     Company:
     <select ng-model="selectedCompanyIndex" ng-change="update(companysData.companys)">
         <option ng-repeat="c in companysData.companys" value="{{$index}}" ng-selected="c.company.sid == selectedCompany.company.sid">{{c.company.company_name}} - {{c.company.link}}</option>
     </select>
    <hr>
    {{selectedCompany.company.link}}
</label>

:

function CompanyController($scope, $http) {
    $scope.companysData = {
        "companys": [{
            "company": {
                "link": "\/company\/8256606980000143017",
                "sid": "8256606980000143017",
                "company_name": "Company 29"
            }},
        {
            "company": {
                "link": "\/company\/8256603960000178016",
                "sid": "8256603960000178016",
                "company_name": "Company 1"
            }}]
    }
    $scope.update = function(dataSet){
        $scope.selectedCompany = dataSet[$scope.selectedCompanyIndex];
    }
    $scope.selectedCompany = $scope.companysData.companys[0];
}

http://jsfiddle.net/XzfVZ/3/

+5

All Articles