热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

将Require.js与Angular.js一起使用是否有意义?[关闭]

本文翻译自:DoesitmakesensetouseRequire.jswithAngular.js?[closed]ImanewbietoAngular.jsand

本文翻译自:Does it make sense to use Require.js with Angular.js? [closed]

I'm a newbie to Angular.js and trying to understand how it's different from Backbone.js... We used to manage our packages dependencies with Require.js while using Backbone. 我是Angular.js的新手,并试图理解它与Backbone.js的不同之处......我们曾经使用Backbone来管理我们的包依赖关系和Require.js。 Does it make sense to do the same with Angular.js? 使用Angular.js做同样的事情是否有意义?




#1楼

参考:https://stackoom.com/question/qZNz/将Require-js与Angular-js一起使用是否有意义-关闭




#2楼

Yes it makes sense to use angular.js along with require.js wherein you can use require.js for modularizing components. 是的,使用angular.jsrequire.js是有意义的,其中您可以使用require.js来模块化组件。

I can point you to a seed project which uses both angular.js and require.js . 我可以指出你使用both angular.js and require.js的种子项目 。 Hope that helps! 希望有所帮助!




#3楼

This I believe is a subjective question, so I will provide my subjective opinion. 我认为这是一个主观问题,所以我将提出我的主观意见。

Angular has a modularization mechanism built in. When you create your app, the first thing you would do is Angular内置了模块化机制。当您创建应用程序时,您要做的第一件事就是

var app = angular.module("myApp");

and then 然后

app.directive(...);app.controller(...);app.service(...);

If you have a look at the angular-seed which is neat starter app for angular, they have separated out the directives, services, controllers etc into different modules and then loaded those modules as dependancies on your main app. 如果您看一下angular-seed这是一个整洁的角度启动应用程序,他们已将指令,服务,控制器等分离到不同的模块中,然后将这些模块作为依赖项加载到您的主应用程序上。

Something like : 就像是 :

var app = angular.module("myApp",["Directives","Controllers","Services"];

Angular also lazy loads these modules ( into memory) not their script files. Angular也懒得加载这些模块(进入内存)而不是他们的脚本文件。

In terms of lazy loading script files, to be frank unless you are writing something extremely large it would be an overkill because angular by its very nature reduces the amount of code you write. 就延迟加载脚本文件而言,坦率地说,除非你写的东西非常大,否则它将是一种矫枉过正,因为角度本质上减少了你编写的代码量。 A typical app written in most other frameworks could expect a reduction in around 30-50% in LOC if written in angular. 如果以角度编写,在大多数其他框架中编写的典型应用程序可以预期在LOC中减少约30-50%。




#4楼

As @ganaraj mentioned AngularJS has dependency injection at its core. 正如@ganaraj所提到的,AngularJS的核心是依赖注入。 When building toy seed applications with and without RequireJS, I personally found RequireJS was probably overkill for most use cases. 在使用和不使用RequireJS构建玩具种子应用程序时,我个人发现在大多数用例中,RequireJS可能有点过分。

That doesn't mean RequireJS is not useful for it's script loading capabilities and keeping your codebase clean during development. 这并不意味着RequireJS对于它的脚本加载功能没有用,并且在开发过程中保持代码库的清洁。 Combining the r.js optimizer ( https://github.com/jrburke/r.js ) with almond ( https://github.com/jrburke/almond ) can create a very slim script loading story. 将r.js优化器( https://github.com/jrburke/r.js )与杏仁( https://github.com/jrburke/almond )结合起来可以创建一个非常纤薄的脚本加载故事。 However since its dependency management features are not as important with angular at the core of your application, you can also evaluate other client side (HeadJS, LABjs, ...) or even server side (MVC4 Bundler, ...) script loading solutions for your particular application. 但是,由于它的依赖关系管理功能对于应用程序核心的angular不是那么重要,您还可以评估其他客户端(HeadJS,LABjs,...)甚至服务器端(MVC4 Bundler,...)脚本加载解决方案为您的特定应用。




#5楼

Yes, it makes sense. 是的,这是有道理的。


Angular modules don't try to solve the problem of script load ordering or lazy script fetching. Angular模块不会尝试解决脚本加载排序或延迟脚本提取的问题。 These goals are orthogonal and both module systems can live side by side and fulfil their goals. 这些目标是正交的,两个模块系统可以并存并实现其目标。

Source: Angular JS official website 资料来源: Angular JS官方网站





#6楼

Yes it makes sense to use requireJS with Angular, I spent several days to test several technical solutions. 是的,将angularJS与Angular一起使用是有意义的,我花了几天时间来测试几种技术解决方案。

I made an Angular Seed with RequireJS on Server Side. 我在服务器端使用RequireJS制作了一个Angular Seed。 Very simple one. 非常简单。 I use SHIM notation for no AMD module and not AMD because I think it's very difficult to deal with two different Dependency injection system. 我使用SHIM表示法没有AMD模块而不是AMD,因为我认为处理两个不同的依赖注入系统非常困难。

I use grunt and r.js to concatenate js files on server depends on the SHIM configuration (dependency) file. 我使用grunt和r.js来连接服务器上的js文件取决于SHIM配置(依赖)文件。 So I refer only one js file in my app. 所以我在我的应用程序中只引用了一个js文件。

For more information go on my github Angular Seed : https://github.com/matohawk/angular-seed-requirejs 有关更多信息,请访问我的github Angular Seed: https : //github.com/matohawk/angular-seed-requirejs


推荐阅读
  • Electron中使用globalShortcut模块来注册全局快捷键,以实现类似于微信和QQ按快捷键调用剪切窗口的功能。快捷键在应用程序加载完成后进行注册 ... [详细]
  • 1.File类:文件和目录路径名的抽象表现形式2.创建对象:File(Stringpathname)通过给定的路径创建文件对象File(Stringpa ... [详细]
  • 本文分析和介绍了GLo ... [详细]
  • Java中的FileStoregetUsableSpace()方法,带示例 ... [详细]
  • linux filesystem_如何使用cgdb + qemu调试linux内核模块
    如何使用cgdbqemu调试linux内核模块前言Linux代码庞大而繁杂,光看代码会使人头晕目眩,如果能通过调试工具对其代码执行流程进行调试ÿ ... [详细]
  • 找出字符串中重复字符
    2019独角兽企业重金招聘Python工程师标准packagejavaBasic;importjava.util.HashMap;importjava.util.Map; ... [详细]
  • IDEA实用插件Lombok
    LombokLombok是一个可以通过简单的注解形式来帮助我们简化消除一些必须有但显得很臃肿的Java代码的工具,通过使用对应的注解,可以在编译源码的时候生成对应的方法。通常,我们所定义的对象和b ... [详细]
  • socket.io是个基于node.js的快平台实时通讯框架。只用不到10行代码,就可以搭建一个简单的多人实时聊天室。先来看看运行后的效果:socket.io多人聊天室只要简单几 ... [详细]
  • RHEL/CentOS/Fedora Linux命令下安装Google Chrome
    键入以下命令查看当前版本是32还是64$echoYouareusing$(getconfLONG_BIT)bitLinuxdistro.You64 ... [详细]
  • hibernate映射组件映射
    在Hibernate中,component是某个实体的逻辑组成部分,它与实体的根本区别是没有oid(对象标识符),compo ... [详细]
  • ARToolKitunity
    ARToolKit为开源的AR库,相对于高通和easyAr有几点特点:1)开源2)识别项目可以动态添加(详细在后)3)识别文件可以本地生成4)目前只能识别图片(目前为.jpg格式) ... [详细]
  • 十一、构建我们自己的包在本章中,我们将学习如何构建自己的包。编写包可以让我们创建可以在许多应用 ... [详细]
  • 篇首语:本文由编程笔记#小编为大家整理,主要介绍了在单独的JVM上执行新的JavaFX应用程序相关的知识,希望对你有一定的参考价值。 ... [详细]
  • Fixes#3560Itriedtodowhatproposedintheissue(inthisbranchhttps://gith ... [详细]
  • POJ1942   DPaths on a Grid
    Imagineyouareattendingyourmathlessonatschool.Onceagain,youareboredbecauseyourteachertellst ... [详细]
author-avatar
梦里的天真575
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有