1

My problem is that every time select tag is change the value $scope.variationValue inside ProductContooller.js.coffee is undefine. Any idea why its undefine?

ProductContoller.js.coffee

controllers = angular.module('controllers')
controllers.controller("ProductController", [ '$scope', '$routeParams', '$location','Restangular'
  ($scope,$routeParams,$location,Restangular)->

    $scope.update_variation = ()->
      console.log $scope.variationValue <---- undefined why?

    Restangular.one('products', $routeParams.id).get().then (c) ->
      $scope.price = c.cheapest_variant.price
      $scope.product = c
      return
])

product.html.slim

.form-group
  label for="sel1"  Variations:
  select ng-options="variant as variant.opt1_value for variant in product.variants" ng-model="variationValue" ng-change="update_variation()"
  | Value {{variationValue.price}}
Chris Ian
  • 771
  • 1
  • 7
  • 19
  • most likely because you are using a primitive for `ng-model` which is really bad practice. Always have a `dot` in `ng-model` reflecting that you are thus binding to an object in order for inheritance to work – charlietfl May 07 '15 at 12:22
  • @charlietfl What do you mean dot in ng-model? – Chris Ian May 07 '15 at 12:35
  • 1
    one of the more important overall concepts to understand when working with angular . Follow as many of the links as you can in this post [angularjs-dot-in-ng-model](http://stackoverflow.com/questions/17606936/angularjs-dot-in-ng-model) – charlietfl May 07 '15 at 12:37
  • @charlietfl still does not work – Chris Ian May 07 '15 at 13:17
  • You probably have a child scope or several between controller and scope of the element. If you define that object in controller then inheritance will work. Don't have to add properties since `ng-model` will do that for you if they aren't already defined. If you already did that create demo that replicates problem – charlietfl May 07 '15 at 13:26

0 Answers0