小编Ka *_*ech的帖子

AngularJs - RXJS Observable取消订阅

我已经设置了一个RXJS可观察.我有两个组件订阅服务工厂的主题.如何取消订阅所选组件到主题以便按下按钮它会停止收听主题广播?

请参阅我的jsfiddle 取消订阅应用程序

我的代码:

<div ng-app="myApp" ng-controller="mainCtrl">

  <script type="text/ng-template" id="/boxa">
  BoxA - Message Listener: </br>
  <strong>{{boxA.msg}}</strong></br>
  <md-button ng-click='boxA.unsubcribe()' class='md-warn'>Unsubscribe A</md-button>
  </script>
  <script type="text/ng-template" id="/boxb">
    BoxB - Message Listener: </br>
  <strong>{{boxB.msg}}</strong></br>
  <md-button ng-click='boxB.unsubcribe()' class='md-warn'>Unsubscribe B</md-button>
 </script>

  <md-content class='md-padding'>
    <h3>
      {{name}}
    </h3>
    <label>Enter Text To Broadcast</label>
    <input ng-model='msg'/></br>
    <md-button class='md-primary' ng-click='broadcastFn()'>Broadcast</md-button></br>
    <h4>
    Components
    </h4>
    <box-a></box-a></br>
    <box-b></box-b>
  </md-content>

</div><!--end app-->


var app = angular.module('myApp', ['ngMaterial']);
app.controller('mainCtrl', function($scope,msgService) {

   $scope.name = "Observer App Example";
   $scope.msg = 'Message';
   $scope.broadcastFn = function(){
        msgService.broadcast($scope.msg);
   }   
});

app.component("boxA", …
Run Code Online (Sandbox Code Playgroud)

rxjs angularjs

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

Bootstrap Dropdown在Internet Explorer中无法正确设置样式

我在我的角度项目中使用了twitter bootstrap类.对于下拉菜单,样式在Chrome中运行良好但是当我将其加载到IE 11时,它的样式不正确.特别是下拉箭头按钮.

有没有其他人与IE有这个问题?我该如何解决这个问题?请查看我的问题下面的比较照片.

在此输入图像描述

我的html部分也在下面,任何评论都欢迎提前感谢!

 <select class=" btn btn-default"  ng-options="obj for obj in data.finding"
                      ng-model="gapSection.finding"  >
                      <option value="">Please select</option>
</select>
Run Code Online (Sandbox Code Playgroud)

css twitter-bootstrap

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

如何在Angular CLI中更新角度2

如何更新Angular 2版本?我使用Angular CLI 1.0.0-beta.20-4,我尝试了npm update --save但它没有做任何事情.

下面是我的package.json文件.感谢任何帮助.

{
  "name": "todo1",
  "version": "0.0.0",
  "license": "MIT",
  "angular-cli": {},
  "scripts": {
    "start": "ng serve",
    "lint": "tslint \"src/**/*.ts\"",
    "test": "ng test",
    "pree2e": "webdriver-manager update",
    "e2e": "protractor"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "2.2.1",
    "@angular/compiler": "2.2.1",
    "@angular/core": "2.2.1",
    "@angular/forms": "2.2.1",
    "@angular/http": "2.2.1",
    "@angular/material": "^2.0.0-alpha.11-3",
    "@angular/platform-browser": "2.2.1",
    "@angular/platform-browser-dynamic": "2.2.1",
    "@angular/router": "3.0.0",
    "@types/hammerjs": "^2.0.33",
    "@types/lodash": "^4.14.43",
    "angular2-jwt": "^0.1.25",
    "angular2-uuid": "^1.1.0",
    "core-js": "^2.4.1",
    "hammerjs": "^2.0.8",
    "lodash": "^4.17.2",
    "material-design-icons": "^3.0.1",
    "rxjs": "5.0.0-beta.12",
    "ts-helpers": "^1.1.1",
    "zone.js": "^0.6.23"
  },
  "devDependencies": { …
Run Code Online (Sandbox Code Playgroud)

angular

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

打字稿/ JavaScript forEach

我正在做一个关于由Typescript进行词法范围处理的教程,我遇到过一个我以前从未见过的函数.这看起来像是forEach语句中的空函数.在打字稿中它看起来像这样:

fns.forEach(fn=>fn());
Run Code Online (Sandbox Code Playgroud)

在javascript中它看起来像:

fns.forEach(function (fn) { return fn(); });
Run Code Online (Sandbox Code Playgroud)

我从来没有见过这样的功能.谁能解释一下这是如何工作的?具体来说,fn => fn()实际执行的是什么.参考下面的代码,它是执行fns.push还是for循环?如果它是For循环,则没有参考,所以它是如何知道的?

以下是完整代码:

打字稿:

var fns = [];
for(var i=0;i<5;i+=1){
    fns.push(function(){
        console.log(i);
    })
}
fns.forEach(fn=>fn());
Run Code Online (Sandbox Code Playgroud)

JavaScript的

var fns = [];
for (var i = 0; i < 5; i += 1) {
    fns.push(function () {
        console.log(i);
    });
}
fns.forEach(function (fn) { return fn(); });
Run Code Online (Sandbox Code Playgroud)

javascript typescript1.8

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

组件的Angular 1.5 Custom指令

我已经升级到Angular 1.5,它现在支持.component()帮助用户转换到AngularJs 2 的帮助方法.不幸的是,它上面没有很多教程.我有以下简化的自定义指令和模板URL.任何人都可以帮我写.component()表格吗?通过这样做,我应该得到它的基础知识,并且应该能够将它用于更复杂的指令.提前致谢.

指示

angular.module("formText", [])
.directive("formText",['$http','formService','$mdDialog', function($http,formService,$mdDialog){

    return{

                scope:{headId:'&',view:'='},
                link: function(scope,element,attrs){ 
                    scope.show = false;
                    scope.formService = formService;

                    scope.$watch('formService', function(newVal) {
                        scope.content = formService.getContent();                       
                    });
                },
                restrict:"E", 
                replace:true,
                templateUrl:"partials/form/tpl/element/text.html",
                transclude:true
            }//return
}])
Run Code Online (Sandbox Code Playgroud)

模板URL

<div layout='column' flex>
     <md-input-container class="md-block" ng-if="view=='DRAFT'">
        <label>{{label()}}</label>
        <textarea style="border-bottom-color:#FFFFFF;" ng-model="content.value" columns="1" ></textarea>
      </md-input-container>
      <md-input-container class="md-block" ng-if="view=='READ'">
        <label>{{label()}}</label>
        <textarea style="border-bottom-color:#FFFFFF;" ng-model="content.value" columns="1" readonly></textarea>
      </md-input-container>
      <ng-transclude></ng-transclude>
</div>
Run Code Online (Sandbox Code Playgroud)

angularjs angularjs-directive

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

角度信号 - 有什么优势?

我试图了解使用 Angular Signals 的优势。许多解释中都给出了一个计数示例,但我试图理解的是,以这种方式使用信号的优点与我在下面通过变量 myCount 和 myCountDouble 所做的方式相反?

\n

https://stackblitz.com/edit/angular-qtd3ku?file=src/main.ts

\n

这是我的代码+ stackblitz

\n
import \'zone.js/dist/zone\';\nimport { Component } from \'@angular/core\';\nimport { bootstrapApplication } from \'@angular/platform-browser\';\nimport { signal } from \'./signals/signal\';\nimport { computed } from \'./signals/computed\';\nimport { effect } from \'./signals/effect\';\nimport { TestArraysCmp } from \'./testing-arrays.component\';\nimport { TestObjectsCmp } from \'./testing-objects.component\';\n\n/*\n  \xe2\x9a\xa0\xef\xb8\x8f Please keep in mind that this is only the signals implementation. We still depend on zone and current CD strategy to propagate change in the template which might …
Run Code Online (Sandbox Code Playgroud)

signals angular angular-signals

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

适用于PostGres的UUID SHORT()

嗨,我有一个基于MYSQL的开发,并且由于商业软件的许可成本而考虑迁移到PostGres。

在我的MYSQL中,我有多个表,在这些表上我依赖于使用UUID_SHORT()函数作为这些表中的主键。参见链接:Mysql UUID_SHORT信息

PostGres是否具有与UUID_SHORT函数类似的功能?我正在寻找一个uniqiue ID,对序列不感兴趣。同样,基于系统时间的内容(如UUID_SHORT)也会很棒。下面也是我要在MYSQL中获取主键插入的唯一ID时在PHP中使用的类函数。

感谢任何评论,因为这是转移到PostGres或不转移到PostGres的主要原因。

function getUniqueId(){
        //return unique id

        $temp_id = strval(uniqid());
        $temp = $this->conn->prepare('CREATE TEMPORARY TABLE tempId (temp_id VARCHAR(30) PRIMARY KEY, id BIGINT UNSIGNED)');
        $temp->execute();
        $temp = $this->conn->prepare('INSERT INTO tempId(temp_id, id) VALUES(:temp_id, UUID_SHORT())');
        $temp->bindParam(':temp_id', $temp_id, PDO::PARAM_STR);
        $temp->execute(); 
        $temp = $this->conn->prepare('SELECT id FROM tempId WHERE temp_id = :temp_id ');
        $temp->bindParam(':temp_id', $temp_id, PDO::PARAM_STR);
        $temp->execute(); 
        $tempResult= $temp->fetchAll(PDO::FETCH_ASSOC);
        $temp = $this->conn->prepare('DROP TEMPORARY TABLE tempId');
        $temp->execute();
        $temp_id = $tempResult[0]['id'];     
        return $temp_id;
    }
Run Code Online (Sandbox Code Playgroud)

mysql postgresql

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

Angular 2 - 检查属性是否为数组

在Angular 2中,如何检查属性是否为数组?

我尝试过构造函数但得到如下函数:

function Array() { [native code] }
Run Code Online (Sandbox Code Playgroud)

我的代码:

let content: any = {id: '1324234', value:{id:null}};
if(content.value.constructor === 'Array'){
 console.log('It is an array');
} else {
 console.log('Not an array');
}
Run Code Online (Sandbox Code Playgroud)

angular

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

CSS半拱围绕整圆

我试图在下面的整圆周围创建一个半拱.我如何在CSS中创建它?到目前为止,我只创建了圆圈但不知道如何进行拱形.

拱圈

.circle {
  width: 45px;
  height: 45px;
  border-radius: 50%;
  font-size: 20px;
  color: #fff;
  line-height: 45px;
  text-align: center;
  position: relative;
  background: #BDBDBD;
}
Run Code Online (Sandbox Code Playgroud)
<div class="circle">1</div>
Run Code Online (Sandbox Code Playgroud)

css css-shapes

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

离子4 - 离子输入双向结合

在Ionic 4中你如何进行双向绑定.在Ionic 3中,我会做以下事情:

<ion-item color="light"> <ion-input type="string" placeholder="Username" [(ngModel)]="username"></ion-input> </ion-item>
Run Code Online (Sandbox Code Playgroud)

但是在Ionic 4中我收到以下错误:

Can't bind to 'ngModel' since it isn't a known property of 'ion-input'.
1. If 'ion-input' is an Angular component and it has 'ngModel' input, then verify that it is part of this module.
2. If 'ion-input' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("d>
          <ion-item …
Run Code Online (Sandbox Code Playgroud)

ionic-framework ionic4

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