microtekblue
microtekblue

Reputation: 29

What does this.$ mean in Angular?

What does this.$ mean in Angular?

I see cases where 'this' is set to a variable such as var vm = this;

Then vm is used like vm.$.Something ..

What does the vm.$ mean?

This is a classy angular example:

var app = angular.module('app', ['ngAnimate','angular-growl', 'classy']);

app.classy.controller({

  name: 'TodoController',

  inject: ['$scope', 'growl', 'todoStorage'],

  data: {
    items: 'todoStorage.get()'
  },

  init: function() {
    this._resetTodoEntry();
  },

  watch: {
    '{object}items': '_onTodoChange'
  },

  methods: {

    _getRemaining: 'items | filter:{ completed: false }',

    _onTodoChange: function() {
      this.$.remainingCount = this._getRemaining().length;
      this.todoStorage.put(this.items);
    },

Upvotes: 2

Views: 853

Answers (1)

Rogerio Soares
Rogerio Soares

Reputation: 1613

It refer to $scope (classy)

Accessing $scope and dependencies Dependencies are available using this.DependencyName. To access the $scope You can simply write this.$.foo = 'bar'; instead of this.$scope.foo = 'bar';. Although you can use still use this.$scope if you prefer.

http://davej.github.io/angular-classy/

Upvotes: 3

Related Questions