在运行链接功能之前,如何确保控制器中的数据已加载到指令中?
使用伪代码,我可以:
<my-map id="map-canvas" class="map-canvas"></my-map>
Run Code Online (Sandbox Code Playgroud)
为我的HTML.
在我的指令中,我可能会有这样的事情:
app.directive('myMap', [function() {
return{
restrict: 'AE',
template: '<div></div>',
replace: true,
controller: function ($scope, PathService) {
$scope.paths = [];
PathService.getPaths().then(function(data){
$scope.paths = data;
});
},
link: function(scope, element, attrs){
console.log($scope.paths.length);
}
}
}]);
Run Code Online (Sandbox Code Playgroud)
以上操作无效,因为console.log($ scope.paths.length); 将在服务返回任何数据之前调用.
我知道我可以通过链接功能调用该服务,但想知道是否有办法在触发链接功能之前"等待"服务调用.
我无法获得在Visual Studio中显示的WPF功能区项目.以下是Visual Studio 2010中存在问题的人的线程链接.
我已经尝试了那里建议的一切但无济于事.
我安装了Visual Studio 2012 Express for Desktop但没有显示任何内容.我试过卸载并重新安装,但没有运气.
我试图在我的控制器中设置最简单的测试,但是,与大多数Laravel一样,没有像样的教程来演示简单的东西.
我可以运行一个简单的测试(在一个名为UserControllerTest的文件中),如下所示:
public function testIndex()
{
$this->call('GET', 'users');
$this->assertViewHas('users');
}
Run Code Online (Sandbox Code Playgroud)
这将调用/ users路由并传入数组用户.
我想和Mockery一样,但是怎么样?
如果我试试这个:
public function testIndex()
{
$this->mock->shouldReceive('users')->once();
$this->call('GET', 'users');
}
Run Code Online (Sandbox Code Playgroud)
我得到一个错误"静态方法Mockery_0_users :: all在这个模拟对象上不存在.
为什么不?我嘲笑用户扩展了Ardent,反过来扩展了Eloquent.为什么::所有不存在的模拟?
顺便说一句,这些是Mockery的设置功能:
public function setUp()
{
parent::setUp();
$this->mock = $this->mock('User');
}
public function mock($class)
{
$mock = Mockery::mock($class);
$this->app->instance($class, $mock);
return $mock;
}
Run Code Online (Sandbox Code Playgroud) 我如何依赖在Laravel中注入Auth?
像这样:
public function __construct(Auth $auth)
{
$this->auth = $auth;
}
Run Code Online (Sandbox Code Playgroud)
如果我这样做,那么这不起作用:
$user_type = Auth::user()->user_type;
Run Code Online (Sandbox Code Playgroud) 我无法将图像转换为使用ngCordova imagePicker选择的base64格式.
为了简单起见,Cordova网站上提供的代码(有效)是这样的:
module.controller('ThisCtrl', function($scope, $cordovaImagePicker) {
var options = {
maximumImagesCount: 10,
width: 800,
height: 800,
quality: 80
};
$cordovaImagePicker.getPictures(options)
.then(function (results) {
for (var i = 0; i < results.length; i++) {
console.log('Image URI: ' + results[i]);
}
}, function(error) {
// error getting photos
});
});
Run Code Online (Sandbox Code Playgroud)
结果数组返回一个结果数组,如:file /// ...但是如何从这里转换?我想要一个函数,您将值传递给(文件)并返回base64字符串.
这是一个尝试这个的函数:
function convertImgToBase64URL(url, callback, outputFormat){
var canvas = document.createElement('CANVAS'),
ctx = canvas.getContext('2d'),
img = new Image();
img.crossOrigin = 'Anonymous';
img.onload = function(){
var dataURL;
canvas.height = …Run Code Online (Sandbox Code Playgroud) 我正在尝试模拟来自特定 api 的大量响应。
我的控制器代码如下所示(为简洁起见进行了修改):
class SomeClass
{
private $guzzle;
public function __construct(\GuzzleHttp\Client $guzzle) {
$this->guzzle = new $guzzle();
}
public function makeRequest(){
$client = $this->guzzle;
$url = 'http//somerurl';
$options = [];
$response = $client->request('POST', $url, $options);
return $response;
}
}
Run Code Online (Sandbox Code Playgroud)
测试看起来像这样(再次编辑)......
public function someTest(){
$mock = $this->createMock(\GuzzleHttp\Client::class);
$mock->method('request')->willReturn([
'response' => 'somedata'
]);
$someClass = new $SomeClass($mock);
$response = $someClass->makeRequest();
$body = $response->getBody();
...
}
Run Code Online (Sandbox Code Playgroud)
此时测试返回“Call to a member function getBody on null”;
如何测试 guzzle 调用的 getBody 响应?
先感谢您...