执行以下单元测试给出"错误:[$ injector:unpr]未知提供者:$ stateProvider < - $ state".我已将angular-ui-router.min.js附加在karma文件中.
describe("Unit tests", function() {
var $rootScope, $injector, $state;
console.log("hello");
beforeEach(inject(function(_$rootScope_, _$state_, _$injector_, $templateCache) {
console.log("hello1");
$rootScope = _$rootScope_;
$injector = _$injector_;
$state = _$state_;
}));
describe("states", function() {
it("verify state configuration", function() {
var config = $state.get("DRaaS");
console.log(config, "cc");
});
});
});
Run Code Online (Sandbox Code Playgroud) 我想使用jest框架.所以在karma.conf文件中,我在框架字段中包含了jest.但它给出错误"WARN [记者]:无法加载"开玩笑",它没有注册!" 当我运行业力开始.我在package.json文件的依赖项中包含了jest包("jest":"〜0.1.39","jest-cli":"~0.4.1").
有人可以给我一些在业力中使用笑话的例子吗?
我想在我的代码中显示名为"id"的变量的值.代码是 -
index.html(第5行) -
<div class="marginTable" data-pubid="<%=id%>" data-count="5">
Run Code Online (Sandbox Code Playgroud)
但每当我执行它时,它都会抛出错误 在jsp文件中的第5行:5处发生错误:/index.html id无法解析为变量.怎么摆脱这个?
我在以下代码中遇到此错误:“错误的意外空对象模式no-empty-pattern”。有谁知道如何解决这个问题?它是一个tsx文件。
const stateToProps = ({}, { data = [], filters = {}, staticFilters =
[{}] }) => {
const allFilters = staticFilters ? Object.assign({}, filters, ...staticFilters) : filters;
const newData = getFilteredRows(allFilters, data);
return {
data: newData,
unfilteredData: data,
};
};
//called like this
export const NodeList = connect<{}, {}, CustomNodeTableProps>(stateToProps)(CustomNodeTable);
Run Code Online (Sandbox Code Playgroud) 我想将表单数据存储到在控制器中声明的数组(它是一个对象数组)中。每次提交表单时,对象格式的表单数据都应该附加到名为 的数组中expenses
。代码是——
控制器.js
angular.module('myApp.controllers', [])
.controller('expenseForm', function($scope, $location) {
$scope.expenses = [{
exTitle: "",
amount: "",
typeOfShare: "",
date: ""
}];
$scope.**submitExpense** = function (expenseInfo) {
}
});
Run Code Online (Sandbox Code Playgroud)
费用.html
<form class="clearBoth" ng-controller="expenseForm" ng-submit="submitExpense(expenseInfo)">
<div class="expenseDesc" ng-model="expenseInfo">
<div class="leftDesc">
<div class="item">
<label for="title">Expense Title</label>
<input type="text" id="exTitle" name="title" ng-model="expenseInfo.exTitle"/>
</div>
<div class="item">
<label for="amount">Total Amount Spend</label>
<input type="text" id="totAmt" name="amount" ng-model="expenseInfo.amount"/>
</div>
<div class="item">
<label for="shareType">Type of Share</label>
<select name="shareType" ng-model="expenseInfo.typeOfShare">
<option value="equal">Equal</option>
<option value="unequal">Unequal</option>
</select>
</div>
</div>
<div …
Run Code Online (Sandbox Code Playgroud) 我想覆盖click事件的事件处理程序。这是我最初附加的事件处理程序。
document.querySelector("[data-id='start-btn']")
.addEventListener("click", function (evt) {
//some code
});
Run Code Online (Sandbox Code Playgroud)
同样,在某些情况下,我想重写此处理程序,并为“ click”事件附加新的处理程序。
//removing
document.querySelector("[data-id='start-btn']")
.removeEventListener("click", function (evt) {
//some code
}, false);
//attaching new
document.querySelector("[data-id='start-btn']")
.addEventListener("click", function (evt) {
//code
});
Run Code Online (Sandbox Code Playgroud)
但是它仍然在执行先前的事件处理程序。我使用过removeEventListener(但是我想它不起作用)。
指导我哪里出问题了。
例如:
<!DOCTYPE html>
<html>
<head>
<title>TEST PAGE</title>
<script type="text/javascript">
"use strict";
function a () {
i = 0;
}
</script>
<body>
<div> TEST </div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
为什么这个html页面在浏览器中执行时没有产生"变量未定义"错误,strict mode
启用了?
我试图在http标头中覆盖POST请求的标头默认值.即使我在函数参数中提供$ httpProvider,但它仍然是抛出错误.
代码是 -
angular.module('myApp.services', ['ngCookies'])
.service('sharedProperties', function ($cookieStore, $http, $httpProvider) {
$httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www- form-urlencoded;charset=utf-8';
});
Run Code Online (Sandbox Code Playgroud)
错误是 -
错误:[$ injector:unpr]未知提供者:$ httpProviderProvider < - $ httpProvider < - sharedProperties
创建了一个工厂'resInterceptor',我正在使用在工厂外定义的函数(requestInterceptor,responseInterceptor).它在函数内部给出错误'$ q is not defined'.但我只想这样做.请建议如何在requestInterceptor和responseInterceptor中访问$ q.
angular.module('resModule', ['ngResource', 'ngCookies'])
.factory('resInterceptor', ['$rootScope', '$q', '$location', resInterceptor]);
function resInterceptor($rootScope, $q, $location) {
return {
request: requestInterceptor,
response: responseInterceptor,
};
}
function requestInterceptor(config) {
return config || $q.when(config); //$q is not defined
}
function responseInterceptor(response) {
return response || $q.when(response);
}
Run Code Online (Sandbox Code Playgroud) javascript ×5
angularjs ×4
arrays ×1
chai ×1
eslint ×1
function ×1
html ×1
jestjs ×1
jsp ×1
karma-runner ×1
mocha.js ×1
reactjs ×1
scriplets ×1
typescript ×1
unit-testing ×1