Javascript 如何正确编写angularJS指令
我对angular有点陌生,我正在键入一个指令,但它不起作用。我想这是因为我没有正确地编写指令,但我似乎在任何地方都找不到答案。我可以使用指令两次吗Javascript 如何正确编写angularJS指令,javascript,angularjs,pug,Javascript,Angularjs,Pug,我对angular有点陌生,我正在键入一个指令,但它不起作用。我想这是因为我没有正确地编写指令,但我似乎在任何地方都找不到答案。我可以使用指令两次吗 'use strict'; /* Directives */ angular.module('myApp.directives', []). directive('appVersion', function (version) { return function(scope, elm, at
'use strict';
/* Directives */
angular.module('myApp.directives', []).
directive('appVersion', function (version) {
return function(scope, elm, attrs) {
elm.text(version);
};
directive('ngFocus', [function() {
var FOCUS_CLASS = "ng-focused";
return {
restrict: 'A',
require: 'ngModel',
link: function(scope, element, attrs, ctrl) {
ctrl.$focused = false;
element.bind('focus', function(evt) {
element.addClass(FOCUS_CLASS);
scope.$apply(function() {ctrl.$focused = true;});
}).bind('blur', function(evt) {
element.removeClass(FOCUS_CLASS);
scope.$apply(function() {ctrl.$focused = false;});
});
}
}
}]);
});
EDIT: Here is my jade template ask asked for in the comments below
login
form(name='signup_form', novalidate='novalidate', ng-submit='signupForm()')
fieldset
legend Signup
.row
.error(ng-show='signup_form.name.$dirty && signup_form.name.$invalid && !signup_form.name.$focused')
label Your name
input(ng-class='{error: signup_form.name.$dirty && signup_form.name.$invalid}', type='text', placeholder='Name', name='name', ng-model='signup.name', ng-minlength='3', ng-maxlength='20', required='required', ng-focus='ng-focus')
.error(ng-show='signup_form.name.$dirty && signup_form.name.$invalid')
small.error(ng-show='signup_form.name.$error.required')
| Your name is required.
small.error(ng-show='signup_form.name.$error.minlength')
| Your name is required to be at least 3 characters
small.error(ng-show='signup_form.name.$error.maxlength')
| Your name cannot be longer than 20 characters
br
label Your email
.error(ng-show='signup_form.email.$dirty && signup_form.email.$invalid && !signup_form.email.$focused')
input(ng-class='{error: signup_form.email.$dirty && signup_form.name.$invalid}', type='text', placeholder='Email', name='email', ng-model='signup.email', ng-minlength='3', ng-maxlength='20', required='required', ng-focus='ng-focus')
.error(ng-show='signup_form.email.$dirty && signup_form.email.$invalid')
small.error(ng-show='signup_form.email.$error.required')
| Your name is required.
small.error(ng-show='signup_form.email.$error.minlength')
| Your name is required to be at least 3 characters
small.error(ng-show='signup_form.email.$error.maxlength')
| Your name cannot be longer than 20 characters
button.button.radius(type='submit') Submit
我注意到的第一件事是语法错误。你有两个指令在上面。如果文件中有多个指令,请按如下方式声明它们:
angular.module('myApp.directives', []).
directive('directiveA', function() {
return {
restrict: 'EA',
link: function(scope, element, attrs) {}
}
}).
directive('directiveB', function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {}
}
}).
directive('directiveC', function() {
return {
restrict: 'E',
link: function(scope, element, attrs) {}
}
});
修复此问题,如果您仍然存在问题,请告知我们。我注意到的第一件事是语法错误。你有两个指令在上面。如果文件中有多个指令,请按如下方式声明它们:
angular.module('myApp.directives', []).
directive('directiveA', function() {
return {
restrict: 'EA',
link: function(scope, element, attrs) {}
}
}).
directive('directiveB', function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {}
}
}).
directive('directiveC', function() {
return {
restrict: 'E',
link: function(scope, element, attrs) {}
}
});
修复此问题,如果您仍然存在问题,请告知我们。我注意到的第一件事是语法错误。你有两个指令在上面。如果文件中有多个指令,请按如下方式声明它们:
angular.module('myApp.directives', []).
directive('directiveA', function() {
return {
restrict: 'EA',
link: function(scope, element, attrs) {}
}
}).
directive('directiveB', function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {}
}
}).
directive('directiveC', function() {
return {
restrict: 'E',
link: function(scope, element, attrs) {}
}
});
修复此问题,如果您仍然存在问题,请告知我们。我注意到的第一件事是语法错误。你有两个指令在上面。如果文件中有多个指令,请按如下方式声明它们:
angular.module('myApp.directives', []).
directive('directiveA', function() {
return {
restrict: 'EA',
link: function(scope, element, attrs) {}
}
}).
directive('directiveB', function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {}
}
}).
directive('directiveC', function() {
return {
restrict: 'E',
link: function(scope, element, attrs) {}
}
});
修复此问题,并让我们知道您是否仍然存在问题。您可以发布html和css吗?我使用了jade,我也会发布,您可以发布html和css吗?我使用了jade,我也会发布,您可以发布html和css吗?我使用了jade,我也会发布,您可以发布html和css吗?我使用了jade,我也会发布