gpt4 book ai didi

javascript - 将 paper.js 集成到 angular.js 中

转载 作者:搜寻专家 更新时间:2023-11-01 04:50:31 24 4
gpt4 key购买 nike

我在将 paper.js 集成到 angular.js 时遇到了这个问题。我的问题是我根本不知道在哪里加载 paperscript 部分。

我有一个 View 和一个 Controller ,但我无法真正将代码放入我所知道的 Controller 中,如果将它放入 View 中,它也不会加载。

我的 Controller 看起来像这样:

    var hash = window.location.hash.split('/');

$scope.status = 'Loading';
var request = jQuery.ajax(system.server, {
'url': system.server,
'headers': {
'Accept': 'application/json',
'Request': system.request + '/hcbs/allocations/resident/' + hash[3],
'Username': system.username,
'Password': system.password
}
})
.always(function(response)
{
signature.constructor();
switch(response.status)
{
case 200:
case undefined:
$scope.$apply(function()
{
$scope.status = '';
var res = JSON.parse(response);
$scope.hcbsAllocations = res.hcbsServiceAllocations;

$scope.change = function(allocationId)
{
console.log(jQuery('[data='+ allocationId +'][name=startDate]').val());
console.log(jQuery('[data='+ allocationId +'][name=endDate]').val());
}

$scope.submit = function(allocationId)
{
// Validate dates

// Make signature popup
$scope.signaturePop = true;
}
});
break;
case 404:
console.log('error ' + response.status);
$scope.$apply(function()
{
$scope.status = 'Problems loading ressource at the moment';
});
default:
console.log(response);
}
});

我的观点是这样的:

<div id="app-content">
<div consumer />

<h1>Consumer</h1>

<div ng-show="status">
<div class="notice">
<p>{{status}}</p>
</div>
</div>

<form name="attendance">
<table class="hcbs">
<tr ng-repeat="allocation in hcbsAllocations">
<td class="first"><h3>{{allocation.type}}</h3></td>
<td class="middle">
<input type="datetime-local" name="startDate" ng-model="startDate" ng-change="change(allocation.id)" data="{{allocation.id}}" placeholder="Choose start date" />

<input type="datetime-local" name="endDate" ng-model="endDate" ng-change="change(allocation.id)" data="{{allocation.id}}" placeholder="Choose end date" />
</td>
<td class="last">
<span class="btn" class="submit" data="{{allocation.id}}" ng-click="submit(allocation.id)"><i class="icon-ok icon-large"></i></span>
</td>
</tr>
</table>
</form>
</div>

最佳答案

对此的指令方法:

Check out the jsFiddle

HTML:

<canvas id="canvas" resize draw></canvas>

指令:

app.directive('draw', function () {
return {
restrict: 'A',
link: function postLink(scope, element, attrs) {
var path;
var drag = false;

function mouseUp(event) {
//Clear Mouse Drag Flag
drag = false;
}

function mouseDrag(event) {
if (drag) {
path.add(new paper.Point(event.layerX, event.layerY));
path.smooth();
}
}

function mouseDown(event) {
//Set flag to detect mouse drag
drag = true;
path = new paper.Path();
path.strokeColor = 'black';
path.add(new paper.Point(event.layerX, event.layerY));
}

function initPaper() {
paper.install(window);
paper.setup('canvas');
}

element.on('mousedown', mouseDown).on('mouseup', mouseUp).on('mousemove', mouseDrag);

initPaper();

}
};
});

关于javascript - 将 paper.js 集成到 angular.js 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19133953/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com