我使用angular ui路由器状态提供程序在angularjs app中定义了以下状态.并且,我想用相同的配置定义多个状态,即.使用相同的模板和控制器.
$stateProvider
.state('parent', {
templateUrl: 'parent.html',
abstract: true,
parent: 'apm'
})
.state('parent.list', {
abstract: true,
url: '/list',
templateUrl: 'list.html',
controller: 'ListCtrl'
})
.state('parent.list.closed', {
url: '/q',
templateUrl: 'closed.html'
})
.state('parent.list.details', { // would like to have same template, controller on different state parent.details without list
url: '/:id/:name',
abstract: true,
templateUrl: 'details.html',
controller: 'DetailsCtrl',
resolve: {
.....
.....
}
})
.state('parent.list.details.data', { // would like to have same template, controller on different state parent.details.data without list
url: '/details',
views …Run Code Online (Sandbox Code Playgroud) 我的角度模块"moduleB"中的状态定义如下
$stateProvider
.state('stateB', {
parent: 'stateA',
abstract: true,
templateUrl : baseUrl+'/templates/stateB.html'
})
.state('stateB.details', {
url: '/stateB/details/:param1/:param2',
resolve : {
value3 : ['$localStorage', '$stateParams', function($localStorage, $stateParams){
return $localStorage.value3[$stateParams.param1];
}]
},
views : {
'view1' : {
templateUrl : baseUrl+'/templates/view1.html',
controller: 'View1Ctrl'
},
'view2' : {
templateUrl : baseUrl+'/templates/view2.html',
controller : 'View2Ctrl'
}
}
})
Run Code Online (Sandbox Code Playgroud)
我想为"解决"编写单元测试,这是我的茉莉花单元测试.
var rootScope, state, injector, mockLocalStorage, httpBackend;
beforeEach(module('moduleB'));
beforeEach(inject(function($rootScope, $state, $injector, $localStorage, $httpBackend) {
rootScope = $rootScope;
state = $state;
injector = $injector;
httpBackend = $httpBackend;
mockLocalStorage …Run Code Online (Sandbox Code Playgroud) 我有一个输入文本框,我想将输入限制为只有字母数字(0-9,az,AZ),最大长度为15.
我试图在angularjs中实现这一点.
<input type="text" id="trackNumber" maxlength="15" ng-pattern="/^[a-zA-Z0-9]*$/" placeholder="" class="form-control" ng-model="trackNumber"/>
Run Code Online (Sandbox Code Playgroud)
将"maxlength"设置为15时,用户无法在框中键入第16个字符.
同样,当用户键入任何特殊字符或空格时,我想阻止"按键"事件.目前,ng-pattern似乎不会阻止用户输入无效输入.
怎么办呢?
任何帮助是极大的赞赏.