加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – ng -inc with $state.go()来自ui-router无法正常工

发布时间:2020-12-17 07:25:44 所属栏目:安全 来源:网络整理
导读:我有这个: ng-include src="'app/components/widgets/buttonbar.html'"/ng-include 这包括来自/ customers路由和/ customers /:id路由的按钮.我可以动态添加带动作的按钮.当我去客户时,我使用此服务界面添加按钮: this.buttons = [] this.addButton = fun
我有这个:
<ng-include src="'app/components/widgets/buttonbar.html'"></ng-include>

这包括来自/ 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')
    }
  }

像我的客户列表那样:

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')
  })
}

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

buttonSvc.addButton('goBack','Go Back','toTheGrid()',2)

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

$scope.toTheGrid = function(){
    $state.go('customers.list')
  }

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

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

看两个按钮:
<button ng-click="foo()">click</button>
<button ng-click="{{'foo()'}}">click</button>

第一次工作,第二次没有. (生成的html是一样的)
见plunk:http://plnkr.co/edit/znFa6lGUGmQ0bYw097zH?p=preview
原因很简单 – 在第二种情况下,’foo()’被视为基本字符串.

所以只需修改代码即可将函数传递给addButton.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读