【问题标题】:can i call more than one function in isolated scope?我可以在隔离范围内调用多个函数吗?
【发布时间】:2017-04-13 13:04:42
【问题描述】:

您好,我正在尝试从隔离范围内调用父范围上的函数。我有 2 个功能,但只有一个功能在工作,但第二个总是不工作,

.directive('dirctiveName', function () {
        return {
            restrict: 'AE',
            replace:true,
            scope: {
                parent_function1: '&',
                parent_function2: '&',
                alert: '=',
                isorder: '='
            },
            templateUrl: "app/pages/dashboard/card.html",
            controller: function ($scope, $interval) {

                $scope.function2= function () {
                    $scope.parent_function2();
                };

                $scope.function1 = function () {
                    $scope.parent_function1();
                };
          }

我有一个带有dashboardCtrl 控制器的dashboard.html,它包含

  $scope.parent_function1= function () {
         //  will do some code
        };

  $scope.parent_function2= function () {
            //  will do some code
        };

这里是 card.html 代码

<div class="card-header" style="background-color:{{color}}"> 
   <button ng-click="function1()" class=" btn btn-success">
     call function1
   </button> 
   <button ng-click="function2()" class=" btn btn-success"> 
     call function2 
   </button>
</div>

指令只运行一个函数吗??

谢谢

【问题讨论】:

  • 请添加或链接到一个最小的工作示例。
  • 你在哪里调用这些函数?来自card.html?也发布您的card.html。此外,任何控制台错误?
  • 我已经更新了帖子

标签: angularjs angular-directive


【解决方案1】:

我发现了问题,我忘记将属性添加到指令中

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-12
    • 1970-01-01
    • 2015-09-05
    • 2014-03-30
    • 1970-01-01
    相关资源
    最近更新 更多