GVKun编程网logo

angularjs – 在角度app中使用$$rAF(angularjs api)

25

在本文中,我们将为您详细介绍angularjs–在角度app中使用$$rAF的相关知识,并且为您解答关于angularjsapi的疑问,此外,我们还会提供一些关于angular4–如何在角度4中使用其

在本文中,我们将为您详细介绍angularjs – 在角度app中使用$$rAF的相关知识,并且为您解答关于angularjs api的疑问,此外,我们还会提供一些关于angular4 – 如何在角度4中使用其他、angularjs – $scope的提供者!在角度2应用程序中使用角度1指令时出错、angularjs – angular.bootstrap运行多个角度应用程序、angularjs – angular.ui.popover不使用最新的角度1.3.3和angular.ui.bootstrap 0.12.0的有用信息。

本文目录一览:

angularjs – 在角度app中使用$$rAF(angularjs api)

angularjs – 在角度app中使用$$rAF(angularjs api)

我正在创建一个指令来动画一系列图像(允许播放,停止和步进).为了获得最佳性能,我想使用requestAnimationFrame.我注意到角度源中有一个requestAnimationFrame服务,前缀是双美元符号($$rAF),我认为这表明它不是为了公共消费.为什么这个和使用这个服务有什么缺点而不是自己创建一个?

解决方法

Why is this

引入它来替换$animate服务中动画的$timeout:

use requestAnimationFrame instead of a timeout to issue a reflow

在AngularJS 1.2.9的更改日志中

what downsides are there to using this service as opposed to creating one myself?

>您必须提供公共API
>包括任何issues in $$raf
>文档缺乏

参考

> AngularJS 1.2.9 Changelog: Features – $animate
> AngularJS requestAnimationFrame unit tests: rafSpec.js

angular4 – 如何在角度4中使用其他

angular4 – 如何在角度4中使用其他

我使用角度4,我想在这个例子中使用ngIf else:
<div *ngIf="isValid">
  content here ...
</div>

<div *ngIf="!isValid">
 other content here...
</div>

如何用其他方式实现相同的行为?

角4.0.0决赛:

使用其他:

<div *ngIf="isValid;else other_content">
    content here ...
</div>

<ng-template #other_content>other content here...</ng-template>

你也可以使用其他的:

<div *ngIf="isValid;then content else other_content">here is ignored</div>

<ng-template #content>content here...</ng-template>
<ng-template #other_content>other content here...</ng-template>

或者一个人:

<div *ngIf="isValid;then content"></div>

<ng-template #content>content here...</ng-template>

演示:

Plunker

细节:

&LT纳克模板> :是Angular自己实现的< template>标签根据MDN:

The HTML <template> element is a mechanism for holding client-side content that is not to be rendered when a page is loaded but may subsequently be instantiated during runtime using JavaScript.

angularjs – $scope的提供者!在角度2应用程序中使用角度1指令时出错

angularjs – $scope的提供者!在角度2应用程序中使用角度1指令时出错

我有一个使用angular-cli构建的角度2应用程序,我需要在我的一个组件中使用角度1指令(从不同的应用程序重用它).我按照以下步骤操作:

https://angular.io/docs/ts/latest/guide/upgrade.html#!#using-angular-1-component-directives-from-angular-2-code

但现在我遇到了这个错误,无法超越它.我正在使用angular2.0.2(我设法在过去使用beta版本构建了一个混合应用程序,但它是一个angular1应用程序,我使用角度2组件与适配器的降级功能).

在我的app.module.ts中我有:

import { UpgradeAdapter } from '@angular/upgrade';
const upgradeAdapter = new UpgradeAdapter(forwardRef(() => AppModule));

const HeroDetail = upgradeAdapter.upgradeNg1Component('heroDetail');

@NgModule({
    imports:      [
        browserModule,...
    ],declarations: [
      ...       
     HeroDetail
     ]
})
export class AppModule { }

我的hero-detail.component.ts看起来像这样:

export const heroDetail = {
  templateUrl: 'hero-detail.html',controller: function() {
  }
};

而我的hero-detail.html看起来像这样:

<h2>Windstorm details!</h2>

我只是通过添加模板尝试在另一个角度2组件中使用该指令:

当我运行服务时,应用程序编译正常,但当我尝试加载页面时,我得到上述错误.

关于如何向前推进的任何建议?

解决方法

看来你的引导逻辑不正确.

它实际上不是很明显,请确保:

>你不用@NgModule({bootstrap:[…]})引导任何ng2组件.相反,您应该在主模块中使用空的ngdobootstrap(){}方法.
>根模板是ng1模板.即在index.html中,您应该只有ng1组件或降级的ng2组件.您可以将ng2组件作为根,但是您需要先将其降级.

官方升级指南包含DOM结构的示例:

enter image description here

…确保ng2注射器具有ng1所需的所有提供者.

angularjs – angular.bootstrap运行多个角度应用程序

angularjs – angular.bootstrap运行多个角度应用程序

这不是Twitter Bootstrap问题……

我有一个用例需要加载单独的角度应用程序.

根据几个堆栈溢出问题和this google thread,它是可行的.但是,我无法让它发挥作用.

看文档:

http://docs.angularjs.org/api/angular.bootstrap

看起来你需要提供元素(如何获取元素的句柄?),然后如何将它与配置,控制器等联系起来.这对路由有何影响?似乎一个应用程序使用否则另一个使用否则,第二个将覆盖第一个?

谢谢!

要获取对您的应用程序的引用,您可以执行以下操作:
var first = document.getElementById('firstapp-id');
var second = document.getElementById('secondapp-id');

angular.bootstrap(angular.element(first),['firstapp']);
angular.bootstrap(angular.element(second),['secondapp']);

其中’firstapp’和’secondapp’是模块/应用程序名称,’firstapp-id’和’secondapp-id’是每个应用程序(或您最喜欢的DOM元素)的容器div的id.只需以通常的方式定义您的应用:

var firstapp = angular.module('firstapp',[]);
var secondapp = angular.module('secondapp',[]);

angularjs – angular.ui.popover不使用最新的角度1.3.3和angular.ui.bootstrap 0.12.0

angularjs – angular.ui.popover不使用最新的角度1.3.3和angular.ui.bootstrap 0.12.0

我创造了这支笔:

http://codepen.io/anon/pen/vEOKEK

如果我使用角度为1.2.X,它会起作用,但是一旦我进入1.3就会死掉.我需要能够使用popover-template.

<p>
    <button popover-placement="bottom" popover-template="calendar.html">Date Picker</button>
  </p>

  <script id="calendar.html" type="text/ng-template">
    <div ng-model="date">
      <datepicker show-weeks="false"></datepicker>
    </div>
    <hr />
    <div>{{ text }}</div>
  </script>
好的底线是 – 我花了HOURS尝试使用angular.ui.popover来做到这一点,但它并没有设计为允许自定义的html模板.我切换到nsPopover角度,我设置.更灵活,更好的选择. angular.ui中的工具提示/ popover仅适用于最小的用例,非常小的我永远不会看到它.

今天的关于angularjs – 在角度app中使用$$rAFangularjs api的分享已经结束,谢谢您的关注,如果想了解更多关于angular4 – 如何在角度4中使用其他、angularjs – $scope的提供者!在角度2应用程序中使用角度1指令时出错、angularjs – angular.bootstrap运行多个角度应用程序、angularjs – angular.ui.popover不使用最新的角度1.3.3和angular.ui.bootstrap 0.12.0的相关知识,请在本站进行查询。

本文标签: