小编Ka *_*ech的帖子

AngularJS 1.5+组件不支持Watchers,解决方法是什么?

我一直在将自定义指令升级到新的组件架构.我读过组件不支持观察者.它是否正确?如果是这样,您如何检测对象的更改?对于一个基本的例子,我有自定义组件myBox,它有一个带有游戏绑定的子组件游戏.如果游戏组件中有更改游戏,我如何在myBox中显示警告消息?我明白有rxJS方法是否有可能纯粹在棱角分明?我的JSFiddle

JavaScript的

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

   $scope.name = "Tony Danza";

});

app.component("myBox",  {
      bindings: {},
      controller: function($element) {
        var myBox = this;
        myBox.game = 'World Of warcraft';
        //IF myBox.game changes, show alert message 'NAME CHANGE'
      },
      controllerAs: 'myBox',
      templateUrl: "/template",
      transclude: true
})
app.component("game",  {
      bindings: {game:'='},
      controller: function($element) {
        var game = this;


      },
      controllerAs: 'game',
      templateUrl: "/template2"
})
Run Code Online (Sandbox Code Playgroud)

HTML

<div ng-app="myApp" ng-controller="mainCtrl">
  <script type="text/ng-template" id="/template">
    <div style='width:40%;border:2px solid black;background-color:yellow'> …
Run Code Online (Sandbox Code Playgroud)

angularjs angularjs-directive angularjs-scope angularjs-components angularjs-1.5

76
推荐指数
2
解决办法
5万
查看次数

Angular 2/4/6/7 - 使用路由器进行单元测试

在Angular 2.0.0中,我正在测试使用Router的组件.但是我得到'提供的参数与呼叫目标的任何签名都不匹配'.错误.在spec.ts中的Visual Studio代码中,新的Router()以红色突出显示

如果有人能让我知道正确的语法是什么,我真的很感激?提前致谢.我的代码如下:

spec.ts

import { TestBed, async } from '@angular/core/testing';
import { NavToolComponent } from './nav-tool.component';
import { ComponentComm } from '../../shared/component-comm.service';
import { Router } from '@angular/router';

describe('Component: NavTool', () => {
  it('should create an instance', () => {
    let component = new NavToolComponent( new ComponentComm(), new Router());
    expect(component).toBeTruthy();
  });
});
Run Code Online (Sandbox Code Playgroud)

组件构造函数

constructor(private componentComm: ComponentComm, private router: Router) {}
Run Code Online (Sandbox Code Playgroud)

unit-testing karma-jasmine angular angular6 angular7

56
推荐指数
4
解决办法
5万
查看次数

Angular 2事件发射器vs Subject

在Angular 2中,Event Emitter和Subject宣布活动有什么区别?似乎事件发射器的声明要简单得多...... Angular 2首选哪种方式?

dataRefreshEvent = new EventEmitter();

private companyDataAnnouncedSource = new Subject();
companyDataAnnouncedSource$ = this.companyDataAnnouncedSource.asObservable();
Run Code Online (Sandbox Code Playgroud)

angular

51
推荐指数
4
解决办法
2万
查看次数

NgFor中与NgModel的Angular 2 - 2路绑定

在Angular 2中,如何使用NgFor在重复列表中与NgModel进行双向绑定.下面是我的plunkr和代码,但我收到一个错误.

Plunkr

@Component({
  selector: 'my-app',
  template: `
  <div>
    <div *ngFor="let item of toDos;let index = index;">
      <input [(ngModel)]="item" placeholder="item">
    </div>
    Below Should be binded to above input box
    <div *ngFor="let item of toDos">
      <label>{{item}}</label>
    </div>
  </div>
  `,
  directives: [MdButton, MdInput]
})
export class AppComponent { 
  toDos: string[] =["Todo1","Todo2","Todo3"];
  constructor() {}
  ngOnInit() {
  }
}
Run Code Online (Sandbox Code Playgroud)

typescript angular

45
推荐指数
2
解决办法
5万
查看次数

角度材质 - 如何在md工具栏中将元素定位到右侧

我在工具栏中使用FAB快速拨号.但是我无法将它浮动到工具栏的右侧.我试过风格:"浮动:正确"没有运气.还尝试了flex offset ="55",但是在调整窗口大小时这不起作用.基本上无论窗口大小如何,我都希望按钮位于蓝色工具栏容器内的最右侧.任何有关这方面的帮助将受到高度赞赏.见下面的照片和代码:

工具栏

<md-toolbar layout-fill layout-padding layout="row" style="background-color: #3F51B5;color:white;text-align:text-center;">
    <div layout="row">
        <i class="fa fa-users fa-2x" flex></i>
        <h1 class="md-title" style="color:white">Org Chart</h1>                                 
    </div>  
    <div class="lock-size" flex offset="55">
        <md-fab-speed-dial md-direction="left" ng-class="md-fling">
            <md-fab-trigger>
                <md-button aria-label="menu" class="md-fab md-accent">
                    <md-tooltip>
                      Actions
                    </md-tooltip>
                    <md-icon md-svg-src="img/icons/ic_view_module_48px.svg"></md-icon>
                </md-button>
            </md-fab-trigger>
            <md-fab-actions>
                <md-button aria-label="view" class="md-fab md-raised md-mini" >
                    <md-tooltip>
                      View Chart
                    </md-tooltip>                               
                    <md-icon md-svg-src="" style="color:black" ng-show="cDP.read" ng-click="paneShowFn('read')"></md-icon>
                </md-button>
                <md-button aria-label="add" class="md-fab md-raised md-mini" >
                    <md-tooltip>
                      Add Chart
                    </md-tooltip>                               
                    <md-icon md-svg-src="img/icons/ic_add_48px.svg" style="color:black" ng-show="cDP.insert" ng-click="paneShowFn('insert')"></md-icon>
                </md-button>
                <md-button aria-label="Settings" class="md-fab md-raised md-mini" >
                    <md-tooltip> …
Run Code Online (Sandbox Code Playgroud)

css angularjs angular-material

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

AngularJS - 过滤的ng-repeat中对象的原始索引

我在对象上使用嵌套的ng-repeat和过滤器.第一个ng-repeat是对gapHeader对象中headerId的过滤.第二个ng-repeat过滤gapSection,sectionId到相应的headerID.

我有一个编辑页面,它在一个单独的模态窗口中.目的是编辑对应于子对象的headerID和sectionID的内容.这也有一个单独的控件.数据通过服务共享.

我的问题我有一个按钮用于每个gapSection子对象,它打开编辑页面模态,当我将每个部分中当前部分的$ index值传递给服务时,我得到的$ index仅对应于第二个ng-重复?例如,如果我单击gapSection上的2 ng-repeat内的按钮(headerId:2,sectionId:2),我得到$ 1的索引.我需要$ index为2,它对应于gapSection中的子对象位置.

是否可以传递真正的$ index,它对应于gapSection的原始未过滤对象中定义的$ index?感谢对此的任何评论,谢谢!

宾语:

var data ={
gapHeader:[{headerId:1,name:"General Requiremets",isApplicable:true},
                    {headerId:2,name:"Insurance",isApplicable:false}],


gapSection:[{headerId:1,sectionId:1,requirement:"A facility is required to have company structure",finding:null,cmeasures:null,cprocedures:null,personResp:null,isAction:null},
        {headerId:2,sectionId:1,requirement:"Organisation must have public liablity",finding:null,cmeasures:null,cprocedures:null,personResp:null,isAction:null},
        {headerId:2,sectionId:2,requirement:"Facility must hold workers compensation insurance",finding:null,cmeasures:null,cprocedures:null,personResp:null,isAction:null}]



};
Run Code Online (Sandbox Code Playgroud)

angularjs

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

Windows 10 - WAMP橙色

我已经在我的Windows 10企业机器上安装了WAMP 64位服务器.但是我得到一个橙色图标.我检查过以下内容:

  1. Apache - >服务,启动/恢复服务显示为灰色,停止服务为红色.另外测试端口80给了我:

您的端口80实际上由以下用户使用:服务器:Apache/2.4.9(Win64)PHP/5.5.12

  1. Mysql - >服务,启动/恢复服务是绿色的.当我点击它时没有任何反应.

  2. 我试过关掉Windows防火墙,没有任何反应.

  3. 我已经检查了Skype,但它实际上没有安装在我的机器上.在命令提示符中尝试了netstat -b,我看不到端口80的任何内容

  4. 搜索mysql-bin.index删除但没有出现.

对我接下来可以尝试的任何帮助都将不胜感激.谢谢

更新以下RiggsFolly建议下面是我通过windows事件记录器从MySQL获得的错误:

    2015-08-08 08:31:08 7024 [Note] Plugin 'FEDERATED' is disabled.
2015-08-08 08:31:08 18ec InnoDB: Warning: Using innodb_additional_mem_pool_size is DEPRECATED. This option may be removed in future releases, together with the option innodb_use_sys_malloc and with the InnoDB's internal memory allocator.
2015-08-08 08:31:08 7024 [Note] InnoDB: Using atomics to ref count buffer pool pages
2015-08-08 08:31:08 7024 [Note] InnoDB: The InnoDB memory heap is disabled
2015-08-08 08:31:08 7024 …
Run Code Online (Sandbox Code Playgroud)

wamp

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

Angular Material:md-datepicker CSS显示问题

我已升级到Angular Material 0.11.1.我正在使用Angular JS v1.4.6.我正在尝试实现新的日期选择器功能.我遇到的问题是当我使用标准代码时如下:

<md-content>
<h4>Standard date-picker</h4>
<md-datepicker ng-model="myDate" md-placeholder="Enter date"></md-datepicker>
</md-content>
Run Code Online (Sandbox Code Playgroud)

当我选择选择器时,我得到一个奇怪的显示问题,其中一半的屏幕是灰色的,可以看到部分日期选择器框.一旦执行此操作并尝试使用弹出框选择任何其他内容,就会发生同样的事情.任何人都知道为什么会这样,以及如何解决它?

下图:

在照片之前 选择日期后

angularjs angular-material

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

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万
查看次数

Angular 2 - ngFor管道后的索引

在Angular 2中使用ng时,如何在数组通过管道后获取对象内的原始索引?

例如,如果我有一个对象数组,如下所示:

list =  [{type:"A",id:111},{type:"A",id:222},{type:"B",id:333},{type:"A",id:444},{type:"B",id:555}];
Run Code Online (Sandbox Code Playgroud)

并使用以下管道:

@Pipe({
  name: 'appFilter',
  pure: false
})
export class AppFilterPipe implements PipeTransform {
// Single Argument Filter
  transform(values: any[], arg1: any, arg2: any): any {
    return values.filter(value => value[arg1] === arg2);
  }
}
Run Code Online (Sandbox Code Playgroud)

我创建一个ngFor如下:

<div *ngFor= "let item of list|AppFilter:'type':'B'|let index=index;trackBy:trackByIndex;">
 {{index}} - {{item.id}}
 <input [(ngModel)]="list[index]" placeholder="item">
</div>
Run Code Online (Sandbox Code Playgroud)

这里的问题是ngFor返回的索引是基于AppFilter返回的索引为0和1的新数组.这将导致输入字段引用错误的索引,即它将显示类型A对象,因为它对应于索引0 ,1在原始列表中.要获得Type BI,确实需要索引2,4.

欣赏这方面的工作.我的组件中的trackByIndex目前看起来像:

trackByIndex(index: number, obj: any): any {
    return index;
  }
Run Code Online (Sandbox Code Playgroud)

angular

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