用户访问首页的时候,会默认路由到注册页面register.htm,而register.htm中定义了属性指令ensure-unique,但是directive.js中指令没有绑定上,指令没有起作用,不知道是何原因,前端没有报错,请帮忙看下
首页index.htm
登陆页面
service.js是空的,留着以后用
app.js
myApp = angular.module("myApp", ["ui.bootstrap", "ngRoute"]);
myApp.config(['$routeProvider',
function ($routeProvider) {
$routeProvider.
when('/index', {
templateUrl: 'templates/index.htm'
}).
when('/register', {
templateUrl: 'templates/register.htm'
}).
when('/login', {
templateUrl: 'templates/login.htm'
}).
otherwise({
redirectTo: '/register'
});
}]);
register.htm 注册页面,这里增加了属性指令ensure-unique
directive.js
myAppDirective=angular.module("myAppDirective",[]);
myAppDirective.directive('ensureUnique', ['$http', function ($http) {
return {
require: 'ngModel',
link: function (scope, ele, attrs, c) {
console.log("executed!");
ele.bind('blur', function () {
if (attrs.ensureUnique == "username") {
$http({
method: 'POST',
url: 'check/' + attrs.ensureUnique + ".html",
data: {"username": scope.username}
}).success(function (data, status, headers, cfg) {
c.$setValidity('unique', true);
}).error(function (data, status, headers, cfg) {
c.$setValidity('unique', false);
});
} else if (attrs.ensureUnique == "email") {
$http({
method: 'POST',
url: 'check/' + attrs.ensureUnique + ".html",
data: {"email": scope.email}
}).success(function (data, status, headers, cfg) {
c.$setValidity('unique', true);
}).error(function (data, status, headers, cfg) {
c.$setValidity('unique', false);
});
}
});
}
}
}]);
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
已经解决了,没有指令的module注入到myApp的module中
楼主你好,你的问题是怎么解决的?为什么你还写了一个module呢?在app.js一个module不就可以了吗?