我正在编写一个需要ngModel的指令,并添加格式化程序和解析器来操作该值.它工作得很好,但由于操作依赖于外部数据,我必须观看,我正在寻找一种方法来更新这款手表的模型值.我试着打电话$setViewValue但没有任何反应(因为$ viewValue没有改变??).
在下面的简单示例中,对"factor"的更改不会更新模型值:
angular.module('app', []).directive('multiply', multiplyDirective);
function multiplyDirective() {
return {
restrict: 'A',
require: 'ngModel',
scope: {
factor: '=multiply'
},
link: function(scope, elem, attr, ngModel) {
ngModel.$formatters.push(function (value) {
return value / scope.factor;
});
ngModel.$parsers.push(function (value) {
return value * scope.factor;
});
scope.$watch('factor', function () {
// how to run the parsers pipeline to update modelvalue?
ngModel.$setViewValue(ngModel.$viewValue);
});
}
}
}Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular.min.js"></script>
<body ng-app ng-init="factor = 1; value = 1">
<input type="number" ng-model="value" multiply="factor" /> x
<input …Run Code Online (Sandbox Code Playgroud)我对Delphi和Delphi中的接口没有多少经验.
例:
IListModel = interface
function At(row, col : Integer) : String;
end;
MyModel = class(TInterfacedObject, IListModel)
public
function At(row, col : Integer) : String;
procedure ManipulateA;
procedure ManipulateBogus;
end;
Run Code Online (Sandbox Code Playgroud)
有一个视图可以显示实现IListModel接口的对象.
View = class(TForm)
public
constructor Create(model : IListModel); reintroduce;
end;
Run Code Online (Sandbox Code Playgroud)
我的应用程序拥有MyModel实例
MyApp = class({...})
strict private
model : MyModel;
public
// ...
end;
Run Code Online (Sandbox Code Playgroud)
在应用程序中,我创建模型并使用它.
procedure MyApp.LoadModel;
procedure MyApp.OnFoo;
begin
model.ManipulateBogus;
end;
Run Code Online (Sandbox Code Playgroud)
现在,我想显示数据
procedure MyApp.ShowModel;
var
v : View;
begin
v := View.Create(model); // implicit to IListView > refCount=1
v.ShowModal; …Run Code Online (Sandbox Code Playgroud) 我想知道什么时候TInterfacedObject派生类的实例被销毁,谁调用析构函数.我写了一个ScopedLock类,当实例超出范围时,它应该自动调用同步对象的Release方法.这是从C++中已知的RAII概念,但是当锁实例超出范围时,我不知道是否保证调用析构函数.
ILock = interface
end;
ScopedLock<T: TSynchroObject> = class(TInterfacedObject, ILock)
strict private
sync_ : T;
public
constructor Create(synchro : T); reintroduce;
destructor Destroy;override;
end;
implementation
{ ScopedLock<T> }
constructor ScopedLock<T>.Create(synchro: T);
begin
inherited Create;;
sync_ := synchro;
sync_.Acquire;
end;
destructor ScopedLock<T>.Destroy;
begin
sync_.Release;
inherited;
end;
{ Example }
function Example.Foo: Integer;
var
lock : ILock;
begin
lock := ScopedLock<TCriticalSection>.Create(mySync);
// ...
end; // mySync released ?
Run Code Online (Sandbox Code Playgroud)
它在一个简单的测试用例中运行良好,但是它安全吗?
我在svg(using ng-switch)中绘制了几个元素并处理它们上的鼠标事件.控制器看起来像这样(有更多类型的元素和更多鼠标事件要处理):
app.controller('MainCtrl', function($scope) {
$scope.elements = [
{ "type": "circle", "x" : 100, "y" : 200 },
{ "type" : "rect", "x" : 50, "y" : 20 }
];
$scope.mousedown = function(element, $event) {
$scope.msg = element.type;
};
});
Run Code Online (Sandbox Code Playgroud)
在鼠标事件处理程序中,我需要鼠标事件的目标模型.我目前的解决方案是添加ng-mousedown="mousedown(element, $event)"到每个svg元素,这对于越来越多的元素类型来说很烦人.
<g ng-switch="p.type">
<g ng-switch-when="circle">
<circle ng-mousedown="mousedown(p, $event)"></circle>
</g>
<g ng-switch-when="rect">
<rect ng-mousedown="mousedown(p, $event)"></rect>
</g>
</g>
Run Code Online (Sandbox Code Playgroud)
有没有办法ng-mousedown只添加到根svg元素并从$event属性中检索单击元素的模型($event.target或者$event.srcElement给我单击的svg元素,如何从中获取模型?).
我正在尝试测试一个Angular服务,它有2个依赖项,一个在$ q上,另一个在'myService'上,它也依赖于$ q.
(function() {
'use strict';
angular.module('myModule').factory('myService', [
'$q',
'apiService',
function($q, apiService) {
var data = null;
function getData() {
var deferred = $q.defer();
if (data === null) {
apiService.get('url').then(function(result) {
data = result;
deferred.resolve(data);
}, function() {
deferred.reject();
});
} else {
deferred.resolve(data);
}
return deferred.promise;
}
return {
getData: getData
};
}
]);
})();
Run Code Online (Sandbox Code Playgroud)
我开始编写一个Jasmine测试,如下所示,但是有问题嘲笑$ q.我想将$ q的真实版本而不是模拟版本注入'myService'和'apiService',但我不知道如何实现这一目标.
'use strict';
describe('My service', function() {
var qSpy, apiServiceSpy;
beforeEach(module('myModule'));
beforeEach(function() {
qSpy = jasmine.createSpyObj('qSpy', ['defer']);
apiServiceSpy = jasmine.createSpyObj('apiServiceSpy', ['get']); …Run Code Online (Sandbox Code Playgroud) 我尝试在运行Windows Server 2008 R2的Hudson上编译Visual C++ 2010 Express解决方案,但由于缺少包含路径而失败.
该项目需要额外的包括中定义的目录,Microsoft.Cpp.Win32.user.props它位于%LOCALAPPDATA%\Microsoft\MSBuild\v4.0.当我登录到服务器时,cd到hudson工作区目录并运行MSBuild项目编译(使用位于我的用户localappdata目录中的props文件).由于哈德森服务作为"本地系统"运行,%LOCALAPPDATA%因此C:\Windows\System32\config\systemprofile\AppData\Local\.所以我放了一份Microsoft.Cpp.Win32.user.props的副本C:\Windows\System32\config\systemprofile\AppData\Local\Microsoft\MSBuild\v4.0.
当我开始在Hudson中构建(使用MSBuild .../verbosity:diag)时,我明白了
UserRootDir = C:\Windows\system32\config\systemprofile\AppData\Local\Microsoft\MSBuild\v4.0
Run Code Online (Sandbox Code Playgroud)
在输出中但不在包含路径中IncludePath.当我将.props文件设置为无效的xml文件(这使得手动构建在开始时失败)时,Hudson构建不报告此失败.当它在Hudson中运行时,似乎MSBuild不解析该文件.
这里出了什么问题?我在哪里放置道具文件或如何定义其他包括Dirs?
问候...
默认的LineSeries实现按固定值对数据点进行排序.这给我这样的数据奇怪的结果:

是否可以绘制一个线序列,其中在原始顺序中的点之间绘制线条?
module ngrFilter{
'use strict';
export class UsersCtrl {
public userCollection: any[];
public userFilter: string;
constructor(){
this.userCollection = [{id:1,name:'John',surname:'Klopper'},
{id:2,name:'Mary',surname:'Schoeman'}];
}
public filterUser(user){
//The this is undefined when using as a custom filter for ng-repeat
console.log(this.userFilter)
if(user.name == this.userFilter ||
user.surname == this.userFilter){
return true;
}
}
}
angular
.module('ngrFilter',[])
.controller('UsersCtrl', UsersCtrl);
}
Run Code Online (Sandbox Code Playgroud)
使用自定义过滤器进行ng-repeat this时,filterUser方法中的属性未定义.有没有办法让这个过滤器工作或我只是做一些愚蠢的事情.
我也尝试在这里添加代码示例:http://fiddlesalad.com/typescript/custom-ngrepeat-filter/
我已经创建了数组列表并将其列出为多个复选框。从那里,如果我选择我存储到数组变量,如果我取消选中它需要从数组中删除。我试过了,但是取消选中的值没有从数组变量中删除。
这是我下面的代码和jsfiddle
的HTML
<div ng-app="myApp" ng-controller="MyCtrl">
<lable ng-repeat="list in lists">
<input type="checkbox" name="chk[]" ng-model="lst" value="{{list.vl}}" ng-change="change()">
{{list.vl}} <br>
</lable>
</div>
Run Code Online (Sandbox Code Playgroud)
脚本
var myApp = angular.module('myApp', []);
myApp.controller('MyCtrl', function($scope){
$scope.lists = [
{'vl' : 1},
{'vl' : 2},
{'vl' : 3},
{'vl' : 4},
{'vl' : 5},
];
$scope.lst = [];
$scope.change = function(){
$scope.lst.push('2');
console.log($scope.lst);
};
});
Run Code Online (Sandbox Code Playgroud) 我有一些用角材料创建的链接.在那里我们的链接和按钮<md-button>.现在我有一个链接,只有当url存在时我才需要添加href属性.否则它不应该有一个href.
原因是,我有下面的主要链接和子链接.具有子链接的主链接不能具有href.如果它确实至少有空的href,只要我点击它以展开子链接,它就会转到索引模板.有些主要链接没有任何子链接.所以,对于他们我需要href和链接与子链接我需要完全删除href.我怎样才能做到这一点?
angularjs ×6
javascript ×6
delphi ×2
interface ×2
charts ×1
checkbox ×1
hudson ×1
jasmine ×1
locking ×1
msbuild ×1
typescript ×1
unit-testing ×1
wpf ×1
wpftoolkit ×1