如何在不同的按钮点击上调用不同的功能?

时间:2016-01-22 08:29:04

标签: angularjs angularjs-directive angularjs-scope

我有两个按钮。我想在按钮点击时调用装饰器功能..在另一个按钮上我想调用服务主要方法..

怎么可能。 我想如果用户点击它显示的第一个按钮

 console.log('--- this os')

如果用户点击它显示的第二个按钮,我想要

 console.log('this is name');

http://plnkr.co/edit/JPTtScno7Saru1GwwkUn?p=preview

//代码在这里

angular.module('app',[]).controller('cntrl',function(newservice,$scope){



  $scope.callDecorator=function(){
    newservice.getName();
  }

  $scope.withoutDecorator=function(){
    newservice.getName();
  }
}).service('newservice',function(){

    this.getName=function(){
      console.log('this is name');
    }

}).decorator('newservice',function($delegate){
  $delegate.getName=function(){
    console.log('--- this os')
  }


  return $delegate
})

0 个答案:

没有答案