如何$window.localStorage使用Jasmine和ngMock对内部使用的工厂进行单元测试?
这是类似于我的东西:
myApp.factory('myData',function ($window) {
return {
message: $window.localStorage['stuff']
}
});
Run Code Online (Sandbox Code Playgroud)
谢谢你!
我正在开发AngularJS应用程序.我正在尝试将值发送$state.go到不同的状态.我正在尝试如下.
这是我的状态:
$stateProvider
.state('Registration.OTPVerification', {
url: '/RegistrationOTPVerification',
templateUrl: 'Registration/RegistrationOTP.html',
controller: 'RegistrationOTPVerification'
});
Run Code Online (Sandbox Code Playgroud)
我正在尝试如下.
var customerid = response.data.ID;
var OTP = response.data.OTP;
$state.go('Registration.OTPVerification', customerid,OTP);
Run Code Online (Sandbox Code Playgroud)
我试图在下面的控制器中接收参数.
(function () {
angular.module('RoslpApp').controller('RegistrationOTPVerification', ['$scope', '$http', '$translatePartialLoader', '$translate', '$state', function ($scope, $http, $translatePartialLoader, $translate, $state, $stateParams) {
var customerid = $stateParams.customerid;
var OTP = $stateParams.OTP;
alert(customerid);
}]);
})();
Run Code Online (Sandbox Code Playgroud)
我无法接收参数.任何帮助,将不胜感激.谢谢.
我有两个组件,我们称它们为 contianer 和 itemList。itemList 有可点击的项目,我需要将点击事件(包括被点击项目的索引)传递给容器。
itemList.ts:
...
@Output()
itemClicked = new EventEmitter<number>();
@Output()
somethingElse = new EventEmitter<void>();
...
this.itemClicked.emit(index);
...
this.somethingElse.emit();
...
Run Code Online (Sandbox Code Playgroud)
容器.html:
...
<itemList (itemClicked)="itemClicked($index)"
(somethingElse)="somethingElse()" ... >
...
</itemList>
...
Run Code Online (Sandbox Code Playgroud)
容器.ts:
...
itemClicked(observer: Observer<number>): void {
// where do I get the index from ?
console.debug('itemClicked( #' + index + ')');
}
somethingElse(observer: Observer<void>): void {
console.debug('somethingElse()');
}
...
Run Code Online (Sandbox Code Playgroud)
问题是container.ts:我从哪里获取索引?
来自的事件somethingElse已成功传递到容器,因此这不可能是完全错误的。事实上,这就是我试图构建 itemClicked 的模式。但我无法将签名更改itemClicked(...)为正确且有效的版本。
我在将 angularJs 应用程序升级到 Webpack4 时遇到问题。
这是我的设置:
vendor.ts
import "angular";
import "angular-i18n/de-de";
import "angular-route";
Run Code Online (Sandbox Code Playgroud)
和
main.ts
import {MyAppModule} from "./my-app.app";
angular.element(document).ready(() => {
angular.bootstrap(document.body, [MyAppModule.name], { strictDi: true });
});
Run Code Online (Sandbox Code Playgroud)
使用 webpack 3。我有一个 commonsChunkPlugin 并且一切正常。
使用 webpack 4,我使用 splitChunks 选项不导入 angularjs 5 次:
webpack.config.ts
...
optimization: {
splitChunks: {
cacheGroups: {
commons: {
name: "commons",
chunks: "initial",
minChunks: 2
}
}
}
}
...
Run Code Online (Sandbox Code Playgroud)
这是正常工作。我只在我的common.js文件中加载了 angularjs 代码。但不幸的是代码被实例化了两次,所以应用程序总是记录警告:
警告:尝试多次加载 AngularJS。
这些块是通过HtmlWebpackPluginhtml加载的。
知道如何删除警告吗?
选择 3.1.1 并尝试添加一个基本的 isMulti 检查列表,我不希望它在每次选择后关闭,所以我添加了
closeMenuOnSelect={假}
但它并不是每次都在 localhost:3000 上工作。(仅当我处于隐身模式时它才起作用)。它不适用于常规的谷歌和火狐浏览器。所以我尝试部署,但在手机上也不起作用。希望获得帮助或使用 isOpen 函数进行智能绕过。谢谢。
<Select
closeMenuOnSelect={false}
components={animatedComponents}
isMulti
options={colourOptions}
hideSelectedOptions={true}
backspaceRemovesValue={true}
/>
Run Code Online (Sandbox Code Playgroud) 这是我用来学习角js 的小提琴
简而言之,JS正在使用的文件:
angular.module('ngApp', [])
.service('myownservice', '$q', function ($timeout, $q) {
this.httpcall = function() {
var httpresp = "1818";
//making an http call over here.
return httpresp;
};
this.UpdateSomeData = function () {
var defer = $q.defer();
myownservice.httpcall().then(function(data) {
defer.resolve(data);
});
return defer.promise;
};
})
.controller('ctrl', function ($scope, myownservice) {
$scope.value = UpdateSomeData();
});
Run Code Online (Sandbox Code Playgroud)
html page:
<div ng-controller="ctrl">{{value}}</div>
Run Code Online (Sandbox Code Playgroud)
但我收到的错误就像是
Argument 'fn' is not a function, got string.
有什么想法吗?
我要使图标和搜索字段在同一行。
<div class="example-header">
<mat-form-field>
<mat-icon>search</mat-icon>
<input matInput (keyup)="applyFilter($event.target.value)" placeholder="Filter">
</mat-form-field>
</div>
Run Code Online (Sandbox Code Playgroud)
上面我添加了我的HTML代码..
我写了很多css,但是我无法获得帮助。
我有一个BoxWithAs组件,定义如下:
const BoxWithAs = styled.div(\n {\n WebkitFontSmoothing: \'antialiased\',\n MozOsxFontSmoothing: \'grayscale\'\n // And more \xe2\x80\xa6\n }\n);\nRun Code Online (Sandbox Code Playgroud)\n一切都很好,但现在我想弃用来自 的默认道具之一@emotion/styled,特别是asprop.
我这样做了:
\ntype BoxWithAsType = typeof BoxWithAs;\ntype BoxProps = Omit<React.ComponentProps<BoxWithAsType>, \'as\'>;\n\n/**\n * Component that does it all.\n */\nconst Box = (props: BoxProps) => {\n return <BoxWithAs {...props}>{props.children}</BoxWithAs>;\n};\nRun Code Online (Sandbox Code Playgroud)\n它确实删除了道具...
\n\n...但现在组件本身丢失了所有StyledComponent类型信息。
我如何构建这个才能实现两者?我的最终目标是弃用该as道具,而是鼓励使用.withComponent(出于 Typescript 的原因)。
angularjs ×4
javascript ×3
typescript ×3
angular ×2
reactjs ×2
css ×1
emotion ×1
events ×1
html ×1
jasmine ×1
react-select ×1
unit-testing ×1
webpack-4 ×1