Use CoffeeScript's class in AngularJS directive controller -
while creating angularjs directives coffeescript using approach:
angular .module('myapp', []) .directive 'mydirective', -> restrict: 'e' controlleras: 'ctrl' controller: -> new class constructor: -> @value = 3
this code works angular 1.2.14—jsbin—but not 1.3.0—jsbin. don't have error in console, nothing. appears controller empty object.
i answered same question in thread: angularjs + coffeescript - 'hello world' directive not working. keeping angular objects proper coffeescript classes. key wrap new directive()
within function block.
class mydirective constructor: (myservice) -> // constructor stuff @controller = mycontroller @controlleras = 'ctrl' restrict: 'e' replace: true scope: attributestuff: '=' link: (scope, element, attr) -> angular.module('my_module').directive 'mydirective', (myservice) -> new mydirective(myservice)
angularjs angularjs-directive coffeescript
No comments:
Post a Comment