[英]How to call a directive in angularjs
I am trying to display the model box through directive and i am not sure where i went wrong but my directive is not at all caled.Can anyone please suggest help.Thanks. 我正在尝试通过指令显示模型框,我不确定我哪里出错了,但我的指令根本没有得到解决。有人可以建议帮助。谢谢。
<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>
My js, 我的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);
};
My directive, 我的指令
(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
};
});
}());
I am trying to display the model box through directive and i am not sure where i went wrong but my directive is not at all caled.Can anyone please suggest help.Thanks. 我正在尝试通过指令显示模型框,我不确定我哪里出错了,但我的指令根本没有得到解决。有人可以建议帮助。谢谢。
This string: 该字符串:
'add-genaral.form.client'
Has a mistake in word 'general', you use this string to get template from url 单词“ general”有误,您可以使用此字符串从url获取模板
/modules/institutions/client/views/add-genaral.form.client.html
Are you sure it is correct? 您确定正确吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.