我一直使用Jasmine进行单元测试,但最近我开始使用Istanbul来给我代码覆盖报告.我的意思是我得到他们试图告诉我的要点,但我不知道每个百分比代表什么(Stmts,Branches,Funcs,Lines).到目前为止谷歌搜索我一直无法找到可靠的解释/资源.
问题:就像我说的那样,我得到了它的要点,但有人可以发布正确的解释或链接到正确的解释吗?
第三个问题:有没有办法确定代码的哪些特定部分未被涵盖?到目前为止,我还没有真正地了解这份报告,我基本上在猜测.
-------------------|-----------|-----------|-----------|-----------|
File | % Stmts |% Branches | % Funcs | % Lines |
-------------------|-----------|-----------|-----------|-----------|
controllers/ | 88.1 | 77.78 | 78.57 | 88.1 |
dashboard.js | 88.1 | 77.78 | 78.57 | 88.1 |
-------------------|-----------|-----------|-----------|-----------|
All files | 88.1 | 77.78 | 78.57 | 88.1 |
-------------------|-----------|-----------|-----------|-----------|
Run Code Online (Sandbox Code Playgroud) 这很简单.您可以轻松地为任何使用的元素提供显示/隐藏功能ng-show="myModelName"
.在官方文档中,他们使用复选框实现此目的.
问题: 您可以在选择选项上使用ng-show吗?我想根据所选的选项显示/隐藏不同的元素.
例如
<select ng-model="myDropDown">
<option value="one">One</option>
<option value="two">Two</option>
<option value="three">Three</option>
</select>
<input ng-show="myDropDown='two'" type="text">
Run Code Online (Sandbox Code Playgroud) 我在表单上使用ng-submit将数据推送到Firebase,一切都按预期工作.我想做的是同时改变观点.在提交按钮本身我有ng-click设置来使用$ location执行一个函数.如果我将changeView函数放在.controller方法中,我就无法使用$ location(具体来说,它说 - "错误:'undefined'不是一个对象(评估'$ location.path')").任何帮助都是超级的.
// This doesn't work and throws the error
myApp.controller('CtrlName', ['$scope', 'angularFireCollection',
function($scope, angularFireCollection, $location) {
$scope.changeView = function(view) {
$location.path(view);
}
}
]);
// This works as expected, but I'm name spacing my functions globally and I will have to change how I'm accessing my Firebase, which isn't really desired.
function CtrlName($scope, angularFireCollection, $location) {
$scope.changeView = function(view) {
$location.path(view);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的模板:
<form role="form" ng-submit="tactics.add(tactic)">
<div class="form-group">
<label>Select Method</label>
<select class="form-control" ng-model="tactic.type">
<option>Email</option> …
Run Code Online (Sandbox Code Playgroud) 我正在构建一个AngularJS应用程序,但我遇到了一个问题.我已经玩了一段时间的框架,我还没有看到像这样或任何例子的文档.我不确定哪条路走下去,指令,模块还是我还没有听说过的东西......
问题:
基本上我的应用程序允许用户添加对象,我们将说这个示例的跨度,它具有可编辑的特定属性:高度和相关标签.我希望使用一组能够控制span对象的所有迭代的输入字段,而不是每个span都有自己专用的高度和标签操作输入字段.
所以我的约.工作代码是这样的:
<span ng-repeat="widget in chart.object">
<label>{{widget.label}}</label>
<span id="obj-js" class="obj" style="height:{{widget.amt}}px"></span>
</span>
<button ng-click="addObject()" class="add">ADD</button>
<input type="text" class="builder-input" ng-model="chart.object[0]['label']"/>
<input type="range" class="slider" ng-model="chart.object[0]['amt']"/>
Run Code Online (Sandbox Code Playgroud)
上面的代码将允许用户添加新对象,但UI显然是硬编码到数组中的第一个对象.
期望的功能:
当用户单击某个对象时,它会更新输入的ng-model的值以绑定到单击的对象.因此,如果单击"object_2",则输入的ng-model更新以与object_2的值同步.如果用户点击"object_4"它会更新输入的ng-model,你就明白了.智能UI,基本上.
我已经考虑过编写一个名为"sync"的指令属性,它可以将ng-model状态推送到绑定的UI.我想完全创建一个新的标签,<object>
并在控制器中构建它们.我已经考虑使用ng-click="someFn()"
它来更新输入字段.所有这些都是"可能性",它们有自己的优点和缺点,但我想在我开始做某事或走错路之前我会问社区.
有没有人这样做过(如果有的话,例子)?如果没有,那么最简洁的AngularJS方法是什么?干杯.
我有一个使用帮助器/包装器指令的Angular模态指令.这样我总是可以使用相同的包装器,只需在不同的模态内容中加载不同的模板.
问题:此代码段有效,但仅适用于模态的第一个生命周期.所以我可以发射模态,关闭模态并再次发射它.但是一旦模态打开,第二次ng-click指令都不起作用.任何提示都只是超级.
用法
<button my-modal="views/login.html">Launch Login-specific Modal</button>
Run Code Online (Sandbox Code Playgroud)
指令模块(app.js)
angular.module('myModal',[])
.directive('modalWrapper', function(){
return {
replace: true,
templateUrl: 'views/modal.html',
controller: function($scope, $element){
$scope.close = function(){
$element.remove();
};
// NOTE: I use this array to showcase that ng-repeat still works the second time although ng-click stops functioning properly.
$scope.others = ["One", "Two", "Three"];
}
}
})
.directive('myModal', function( $compile){
function link(scope, element, attr){
scope.partial = attr.myModal; // NOTE: Loads sub template via ng-include
var ngModal = $compile('<div modal-wrapper></div>')(scope);
element.on('click', function(){
angular.element('body').append(ngModal); …
Run Code Online (Sandbox Code Playgroud) 情况: 我正在移植,或者我应该说尝试将Lakshan Perera的简单jQuery ColorPicker(https://github.com/laktek/really-simple-color-picker)移植到Angular.在回顾SO上的类似问题后,似乎有些人通过控制器分配了插件的范围,但正确的(Angular)方法是将插件包装在指令中.我越来越近了.我能够通过我的新自定义属性在我的视图中正确呈现插件,但我不确定如何设置指令以将输入值传递给属性的值(ng-model).实际的输入更新,但Angular没有监听更改,因此实际上并不知道输入值已更新.官方文档讨论了如何设置自定义属性(http://docs.angularjs.org/guide/directive),
期望的功能 -
<input my-widget="{{color}}" type="text"/> <!-- my-widget instantiates my directive -->
<h1 style="color:{{color}}"></h1> <!-- I would like the input value to dump into the attribute's value, in this case {{color}} -->
Run Code Online (Sandbox Code Playgroud)
这是我到目前为止:
app.directive('myWidget', function(){
var myLink = function(scope, element, attr) {
scope.$watch('element',function(){
var value = element.val();
element.change(function(){
console.log(attr.ngModel); // This is currently logging undefined
// Push value to attr here?
console.log( value + ' was selected');
});
});
var element = $(element).colorPicker();
}
return …
Run Code Online (Sandbox Code Playgroud) 基本上我有一个单页HTML应用程序,其中包含所有固定位置,我只希望一个窗格具有可滚动内容.一切都按预期工作,但我无法滚动到内部容器容器的底部.我已经尝试将所有东西都移到abs pos,我已经尝试了所有我能够找到的解决方案,但是没有骰子.这是一个小提琴(http://jsfiddle.net/yhhjL/),这里是我的标记和CSS的粗略模拟:
HTML
<header>
<p>Company</p>
</header>
<div class="fixed-row-one"></div>
<div class="fixed-row-two"></div>
<div class="fixed-stage-left">
<div class="scrollable">
<table cellpadding="0" cellspacing="0">
<tr>
<td>First</td>
<td>Second</td>
<td>Third</td>
<td>Fourth</td>
</tr>
<tr>
<td>First</td>
<td>Second</td>
<td>Third</td>
<td>Fourth</td>
</tr>
<tr>
<td>First</td>
<td>Second</td>
<td>Third</td>
<td>Fourth</td>
</tr>
<tr>
<td>First</td>
<td>Second</td>
<td>Third</td>
<td>Fourth</td>
</tr>
<tr>
<td>First</td>
<td>Second</td>
<td>Third</td>
<td>Fourth</td>
</tr>
<tr>
<td>First</td>
<td>Second</td>
<td>Third</td>
<td>Fourth</td>
</tr>
<tr>
<td>First</td>
<td>Second</td>
<td>Third</td>
<td>Fourth</td>
</tr>
<tr>
<td>First</td>
<td>Second</td>
<td>Third</td>
<td>Fourth</td>
</tr>
<tr>
<td>First</td>
<td>Second</td>
<td>Third</td>
<td>Fourth</td>
</tr>
<tr>
<td>First</td>
<td>Second</td>
<td>Third</td>
<td>Fourth</td>
</tr>
<tr> …
Run Code Online (Sandbox Code Playgroud) 我已经在API网关后面建立了一个Lambda函数,它可以很好地工作.我有一个托管网站,我只想要某个位置来访问API.
https://www.example.com/(从托管服务器提供html)
https://www.example.com/foobar(返回由Lambda生成并由AWS返回的JSON有效内容)
这是我的服务器块:
location = /foobar {
proxy_pass https://someawsuri;
proxy_redirect default;
}
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试过审阅文档并阅读多篇SO帖子,但我无法做到我想要的.我尝试过的所有东西都产生了错误502 Bad Gateway
.
如何配置nginx向API网关发出请求?
谢谢.
angularjs ×5
angular-ui ×1
angularfire ×1
aws-lambda ×1
controller ×1
css ×1
firebase ×1
html ×1
istanbul ×1
jasmine ×1
javascript ×1
jquery ×1
nginx ×1
positioning ×1
spacing ×1
testing ×1