我有一个跟随控制器:
.controller('ProjectUserAddCtrl', ['$scope', 'ProjectUser', '$q', 'i18nNotifications',
function($scope, ProjectUser, $q, i18nNotifications) {
var buildUnassignedUsers = function(users, project) {
var unassignedUsers = [];
angular.forEach(users, function(user) {
var match;
angular.forEach(project.projectUsers, function(projectUser) {
if(match) {return;}
if(projectUser.user.id === user.id) {
match = true;
}
});
if(!match) {
unassignedUsers.push(user);
}
});
$scope.unassignedUsers = unassignedUsers;
};
$q.all([
$scope.users,
$scope.project
]).then(function(result) {
buildUnassignedUsers($scope.users, $scope.project);
$scope.$watch('project', function(newVal) {
buildUnassignedUsers($scope.users, $scope.project); }, true
);
});
}]);
Run Code Online (Sandbox Code Playgroud)
并在茉莉花中进行以下测试:
describe('ProjectUserAddCtrl', function() {
var ctrl;
beforeEach(function(){
$scope.users = [];
$scope.project = {
projectUsers: …Run Code Online (Sandbox Code Playgroud) 我有一个如此定义的指令:
angular.module('directives.myInput', [])
.directive('myInput', function($parse, $http, $sce){
return {
restrict: 'E',
template: '<input type="text" ng-model="searchStr" />',
controller: function($scope){
$scope.keyPressed = function(event){
$scope.showDropdown = true;
.
.
.
}
}
};
});
Run Code Online (Sandbox Code Playgroud)
然后我在html和指令上面有一个按钮,声明如下:
<div ng-controller="IndexCtrl">
<button ng-click="startNewLog()">Start</button>
<div ng-controller="ItemNewCtrl">
<myInput />
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我想在按钮ng-click上更改/初始化ng-model ="searchStr"模型.我怎样才能做到这一点?
谢谢你们,Jani
我已经实现了身份验证系统,从角度1.0.8升级到1.2.x后,系统无法正常工作.当用户登录时获取令牌.令牌过期时,将调用新令牌的刷新功能.在服务器上成功创建新令牌,并将其存储到数据库.但是客户端没有获得这个新令牌,因此它再次请求一个新令牌,并一次又一次地请求它直到它注销.服务器端(MVC Web Api)工作正常,因此问题必须在客户端.问题必须在重试队列上.下面我粘贴了两个版本的应用程序(1.0.8和1.2.x)的相关代码和控制台跟踪.我现在正在努力奋斗这几天,我无法弄明白.
在下面的链接中,有5个相关的代码块:
代码:http://pastebin.com/Jy2mzLgj
应用程序的控制台跟踪角度为1.0.8:http://pastebin.com/aL0VkwdN
和角度1.2.x:http://pastebin.com/WFEuC6WB
angular.module('security.interceptor', ['security.retryQueue'])
.factory('securityInterceptor', ['$injector', 'securityRetryQueue', '$q',
function ($injector, queue, $q) {
return {
response: function(originalResponse) {
return originalResponse;
},
responseError: function (originalResponse) {
var exception;
if (originalResponse.headers){
exception = originalResponse.headers('x-eva-api-exception');
}
if (originalResponse.status === 401 &&
(exception === 'token_not_found' ||
exception === 'token_expired')){
queue.pushRetryFn(exception, function retryRequest() {
return $injector.get('$http')(originalResponse.config);
});
}
return $q.reject(originalResponse);
}
};
}])
.config(['$httpProvider', …Run Code Online (Sandbox Code Playgroud)