小编tan*_*may的帖子

如何在内部对使用localStorage的AngularJS服务进行单元测试

如何$window.localStorage使用Jasmine和ngMock对内部使用的工厂进行单元测试?

这是类似于我的东西:

myApp.factory('myData',function ($window) {
    return { 
        message: $window.localStorage['stuff'] 
    }
});
Run Code Online (Sandbox Code Playgroud)

谢谢你!

javascript unit-testing local-storage jasmine angularjs

3
推荐指数
1
解决办法
2744
查看次数

如何在Angularjs $ state.go中发送参数?

我正在开发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)

我无法接收参数.任何帮助,将不胜感激.谢谢.

javascript angularjs angular-ui-router

3
推荐指数
1
解决办法
6983
查看次数

Angular 通过 @Output() 将参数传递给父组件

我有两个组件,我们称它们为 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(...)为正确且有效的版本。

events typescript angular

3
推荐指数
1
解决办法
4563
查看次数

AngularJs 多次加载

我在将 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加载的。

知道如何删除警告吗?

angularjs typescript webpack-4

3
推荐指数
1
解决办法
765
查看次数

反应选择“closeMenuOnSelect = {false}”问题

选择 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)

html reactjs react-select

2
推荐指数
1
解决办法
2991
查看次数

当评估值并通过控制器发送时,Angular $ scope.value不会更新

这是我用来学习角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.

有什么想法吗?

javascript angularjs angular-promise

1
推荐指数
1
解决办法
82
查看次数

如何使用材质在同一行中制作图标和占位符?

我要使图标和搜索字段在同一行。

<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,但是我无法获得帮助。

css angular-material angular-material2 angular

1
推荐指数
2
解决办法
6503
查看次数

省略情感风格组件中的特定道具?

我有一个BoxWithAs组件,定义如下:

\n
const BoxWithAs = styled.div(\n  {\n    WebkitFontSmoothing: \'antialiased\',\n    MozOsxFontSmoothing: \'grayscale\'\n    // And more \xe2\x80\xa6\n  }\n);\n
Run Code Online (Sandbox Code Playgroud)\n

一切都很好,但现在我想弃用来自 的默认道具之一@emotion/styled,特别是asprop.

\n

我这样做了:

\n
type 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};\n
Run Code Online (Sandbox Code Playgroud)\n

它确实删除了道具...

\n

在此输入图像描述

\n

...但现在组件本身丢失了所有StyledComponent类型信息。

\n

在此输入图像描述

\n

我如何构建这个才能实现两者?我的最终目标是弃用该as道具,而是鼓励使用.withComponent(出于 Typescript 的原因)。

\n

emotion typescript reactjs styled-components

1
推荐指数
1
解决办法
1280
查看次数