2

What is working: The ng-options contains all names and it is shown in the dropdown-list.

Problem:

  1. At the beginning if nothing is selected, there should the text "Select name..." displayed. But it's empty right now.
  2. I know it has been asked a lot but I didn't found a solution with this case. If I will select some of those options the Error

"Error: [$compile:nonassign] Expression 'undefined' used with directive 'fileWidget' is non-assignable!" occured.

GeometryService.js

angular.module('COMLEAMclient')
.factory('GeometryService', function($resource) {

  var selectedGeometry = {name:'Select name...'};
}

FileWidgetDirective.js

angular.module('COMLEAMclient')
.directive('fileWidget', ['$log', '$parse', function($log, $parse) {

        return {
            scope: {
                data: '=',
                selectedFile: '=',
                updateSelection: '&',
                selected: '=',
                onReadFile: '&',
            },
           ....
        }
    )
}

InputController.js

<div file-widget data="iCtrl.geometryFiles"  update-selection= "iCtrl.setSelectedGeometry(name)" selectedFile= "iCtrl.selectedGeometryFile" on-read-file="iCtrl.saveGeometryFiles(file,name)"></div>

FileWidget.html

<select class="form-control"
    ng-options="elem.name for elem in data"
    ng-model="selectedFile"
    ng-change="onSelectionChange()">
</select>

Any ideas?

scniro
  • 16,844
  • 8
  • 62
  • 106
Marcel Tinner
  • 1,343
  • 11
  • 18

1 Answers1

2

In order to have Select name... you need to have an option element:

<select class="form-control"
    ng-options="elem.name for elem in data"
    ng-model="selectedFile"
    ng-change="onSelectionChange()">
    <option value="">Select name...</option>
</select>

You are trying to assign to an object, and that is non assignable, which is why you're getting the non-assignable error. You need to have a variable that can contain the value the selected option, try:

ng-model="selectedFile.name"
Omri Aharon
  • 16,959
  • 5
  • 40
  • 58
  • I canged my code to but got still the same excepion. probably there is more than just this. – Marcel Tinner May 17 '15 at 07:44
  • @MarcelTinner Perhaps `selectedFile.name` is also non-assignable. Can you share that obj? – Omri Aharon May 17 '15 at 08:27
  • it sould be this on in the GeometryService.js --> var selectedGeometry = {name:'Select name...'}; – Marcel Tinner May 18 '15 at 14:24
  • I don't recommend binding straight from the view to the service's variable. Place it on the controller somewhere. Also now it looks like your variable is private to the GeometryService. – Omri Aharon May 19 '15 at 05:35