How do you access the $on, $emit, $broadcast methods with Controller as syntax?

前端 未结 1 1455
一向
一向 2021-01-01 18:07

Using $scope it\'s easy to emit an event or watch for one.

(function() {
    \"use strict\";

    angular
        .module(\"app\")
        .cont         


        
相关标签:
1条回答
  • 2021-01-01 18:33

    In order to use anything that exists on $scope, you are forced to inject $scope. It's unfortunately that straightforward, which is a shortcoming of the "as" syntax.

    The good news however is that injecting $scope alongside this does not change how the controller as syntax functions, it simply gives you access to all of the event management that lives on $scope.

    It's worth noting that this is one of the primary reasons for what is coming in Angular 2.0...there is a real problem and discrepancy between $scope and the "Controller as" syntax that was bolted on to solve scoping issues in views.

    0 讨论(0)
提交回复
热议问题