2016-11-22 50 views
0

我試圖通過指令顯示模型框,我不確定我出錯的地方,但我的指令根本沒有caled.Can任何人都可以請建議help.Thanks。如何在angularjs中調用指令

<div class="modal fade" id="institutionModal" role="dialog"> 
    <div class="modal-dialog"> 
     <!-- Modal content--> 
     <div class="modal-content">  
      <common-directive-institution field="field" data="data" ng-if="showInstitutionModal"></common-directive-institution> 
     </div> 
    </div> 
</div> 
<button type="button" ng-click="editInstitutionModal('general')" class="btn btn-white">Edit</button> 

我的JS,

$scope.editInstitutionModal = function (type) { 
    $scope.field = {}; 
    $scope.showInstitutionModal = false; 
    if (type === 'basicedit') { 
     $scope.field.field_type = 'edit-institution.form.client'; 
     $scope.field.formName = 'Edit institution (' + vm.institutionObj.name + ')'; 
     $scope.field.saveText = 'Update'; 
    } 
    if(type === 'general'){ 
     $scope.field.field_type = 'add-genaral.form.client'; 
     $scope.field.formName = 'General Info'; 
     $scope.field.saveText = 'Save';   
    } 
    $timeout(function() { 
    $scope.showInstitutionModal = true; 
    $('#institutionModal').modal('show'); 
    $scope.$apply(); 
    }, 10); 
}; 

我的指令,

(function() { 
    'use strict'; 

    angular 
      .module('users') 
      .directive('commonDirectiveInstitution', function ($http, $compile) { 

      var getTemplateUrl = function (field) {   
       var type = field.field_type; 
       var templateUrl = '/modules/institutions/client/views/'; 
       templateUrl += type + '.html'; 
       return templateUrl; 
      }; 

      var linker = function (scope, element) { 
       var templateUrl = getTemplateUrl(scope.field); 
       $http.get(templateUrl).success(function (data) { 
       element.html(data); 
       element.removeAttr('style'); 
       $compile(element.contents())(scope.$parent); 
       }); 
      }; 

      return { 
       template: '<div style="display:none">{{field}}</div>', 
       restrict: 'E', 
       scope: { 
       field: '=' 
       }, 
       replace: true, 
       link: linker 
      }; 
      }); 
}()); 

我想顯示通過指令模式框,我不知道我哪裏錯了,但我的指令是完全沒有caled.Can任何人都可以請建議help.Thanks。

+1

模板:'

{{field}}
' 此模板不顯示任何內容。更改顯示樣式。 哦,我的壞,我看你刪除風格。 –

+0

不相關,但你有這裏的錯字:add-genaral.form.client可能會打破某些東西。 –

+0

謝謝大家......它是我的錯誤bcoz我忘記了建立吞嚥..........對不起 – MMR

回答

0

此字符串:

'add-genaral.form.client' 

先後在單詞「一般」一個錯誤,你用這個字符串從URL獲得模板

/modules/institutions/client/views/add-genaral.form.client.html 

你確定這是正確的?

+0

我改變了它,但沒有用 – MMR