Привет Я пытаюсь реализовать следующие угловую директивы, используя машинопись классы,Issue угловые директивы с использованием машинопись
angular.module('mota.main', []).directive('modalDialog', function() {
return {
restrict: 'E',
scope: {
show: '='
},
replace: true, // Replace with the template below
transclude: true, // we want to insert custom content inside the directive
link: function(scope, element, attrs) {
scope.dialogStyle = {};
if (attrs.width)
scope.dialogStyle.width = attrs.width;
if (attrs.height)
scope.dialogStyle.height = attrs.height;
scope.hideModal = function() {
scope.show = false;
};
},
templateUrl = 'src/app/selection.ts'
};
});
Это шаблон:
<div class='ng-modal' ng-show='show'>
<div class='ng-modal-overlay' ng-click='hideModal()'></div>
<div class='ng-modal-dialog' ng-style='dialogStyle'>
<div class='ng-modal-close' ng-click='hideModal()'>X</div>
<div class='ng- modal-dialog-content' ng-transclude></div>
</div>
</div>
Это мой подход,
export class ModalDialogDirective implements ng.IDirective {
public restrict = "E";
public scope = {show: '='};
public require = ['ngModel'];
public transclude = true;
public templateUrl = 'src/app/selection.ts';
public replace = true;
public link(scope: ng.IScope, element: JQuery, attrs: ng.IAttributes)
{
scope.dialogStyle = {};
if (attrs.width){
scope.dialogStyle.width = attrs.width;
}
if (attrs.height){
scope.dialogStyle.height = attrs.height;
}
scope.hideModal = function() {
scope.show = false;
};
}
}
Это его способ его вызова в html:
<modal-dialog show='modalShown' width='400px' height='60%'>
<p>Modal Content Goes here<p>
</modal-dialog>
Я получаю проблемы как: Свойство 'dialogStyle' не существует в типе '{show: string; }».
Свойство 'width' не существует в типе 'IAttributes'.
Аргумент типа 'typeof ModalDialogDirective' не присваивается параметру типа 'any []'.
Привет @Hugues, но я получаю свойство 'dialogStyle' не существует в типе '{show: string; }». в то время как это то, что я пытаюсь реализовать в Typcript http://jsbin.com/aDuJIku/2/edit?html,css,js – shailbenq
Можете ли вы помочь мне выяснить, что именно эта проблема означает «Тип аргумента типа ModalDialogDirective», не присваивается параметру типа «any []» «Я зарегистрировал его с основным приложением как угловое .module ('modalRun', [ .... ]). директива ('modalDialog', ModalDialogDirective) – shailbenq
ваш второй аргумент в app.directive должен быть массивом? Хотя, похоже, это работает в js, я бы попытался обернуть второй аргумент в .directive и .controller в массиве. –