来自ui-router的$ state.go()的ng-include无法正常工作

dkr*_*ran 8 angularjs angularjs-scope angular-ui-router

我有这个:

<ng-include src="'app/components/widgets/buttonbar.html'"></ng-include>
Run Code Online (Sandbox Code Playgroud)

这包括来自/ customers路由和/ customers /:id路由的按钮.我可以动态添加带动作的按钮.当我去客户时,我使用此服务界面添加按钮:

  this.buttons = []
  this.addButton = function(id, title, classes, href, action, sortOrder){
    console.log(this.buttons)
    var button = {};
    var pushViable = true;
    button.id = id
    button.title = title
    button.classes = classes
    button.href = href
    button.action = action
    button.sortOrder = sortOrder
    angular.forEach(this.buttons, function(index, sort){
      if(button.sortOrder === sort){
        toastr.error('Button Sort Order Exists')
        pushViable = false;
      }
    })
    if(pushViable === true){
      this.buttons.push(button)
      this.buttons = sortButtons(this.buttons)
      $rootScope.$broadcast('buttonBar:update')
    }
  }
Run Code Online (Sandbox Code Playgroud)

像我的客户列表那样:

buttonSvc.addButton('newCustomer','New Customer', 'button small', '#','newCustomer()',0)

$scope.newCustomer = function(){
  var customerModal = $modal.open({
    templateUrl: 'app/customers/newCustomer.html',
    controller: 'customerModalCtrl',
    windowClass: 'small'
  })

  customerModal.result.then(function(){
    $rootScope.$broadcast('customer:update')
  })
}
Run Code Online (Sandbox Code Playgroud)

(从模式开始,使用来自github上的pineconellc的ui-foundation)

  buttonSvc.addButton('goBack','Go Back', 'button small', '#','toTheGrid()',2)
Run Code Online (Sandbox Code Playgroud)

但是,此按钮无效,此代码生效:

  $scope.toTheGrid = function(){
    $state.go('customers.list')
  }
Run Code Online (Sandbox Code Playgroud)

如果我只是制作一个常规按钮并使用该功能,它工作正常.所以我有一个问题.

由于我现在已经获得了赏金,如果您想查看更多代码,请询问并发布相关来源.

Pet*_*nov 1

看两个按钮:

<button ng-click="foo()">click</button>
<button ng-click="{{'foo()'}}">click</button>
Run Code Online (Sandbox Code Playgroud)

第一个工作,第二个不工作。(生成的html是相同的)参见plunk: http: //plnkr.co/edit/znFa6lGUGmQ0bYw097zH? p=preview 原因很简单 - 在第二种情况下,'foo()'被认为只是基本字符串。

因此,只需修改代码以将函数传递给 addButton 即可。