javascript - Use CoffeeScript class in AngularJS controller -
i have presenter class written in coffeescript. it's in file loaded before angularjs controller. can't use class there. how use it?
presenter:
class companypresenter constructor: (company) -> @company = company location: -> if @company.business.city && @company.country_id @company.business.city + ', ' + @company.country_id else if @company.business.city @company.business.city else if @company.country_id @company.country_id else undefined
controller:
@sim.controller 'companyshowctrl', ['$scope', '$http', '$stateparams', 'language' ($scope, $http, $stateparams, language) -> $http.get('businesses/' + $stateparams.id).success((businessattributes) -> $scope.business = businessattributes # doesn't work :( $scope.businesspresenter = new companypresenter($scope.business) )
i tried avoid using service
or factory
, because don't need singleton, want initialize model , able reuse it.
i added line after class definition
@sim.value('companypresenter', companypresenter)
and injected 'companypresenter'
companyshowctrl
.
Comments
Post a Comment