将requireJS与AngularJS一起使用

时间:2015-11-01 22:37:54

标签: javascript angularjs requirejs

我正在学习如何将AngularJS与RequireJs一起使用的教程。我似乎不明白这是如何运作的。

作者创建了一个文件app.js并在文件内添加;

define(function (require) {
    'use strict';

    var angular = require('angular');
    var services = require('./services/services');
    var controllers = require('./controllers/controllers');
    var directives = require('./directives/directives');
    var app = angular.module('App', ['services', 'controllers', 'directives']);
    app.init = function () {
        angular.bootstrap(document, ['App']);
    };
...
})

但是没有显示文件services.js,controllers.js和directives.js的结构。

例如,在services文件中,我假设我有多个服务定义。这是一个很好的结构,因为这意味着我可以在一个脚本中创建多个服务或控制器。我遇到的问题是从中获取服务; var =服务进入App。

1 个答案:

答案 0 :(得分:0)

使用require嵌套或分组文件非常常见 - 所以services / services.js文件(上面的应用程序中需要)可能如下所示:

    .file   "test.c"
.LC0:
    .ascii "\x0a\0"
.LC1:
    .ascii "\033[1;31m.\033[0m\0"
.LC2:
    .ascii "\033[1;31m#\033[0m\0"
.LCtest0:
    .ascii "\033[1;32mdebug\033[0m\0"
.LCtest1:
    .ascii "\033[1;31mdebug\033[0m\0"
.LCtest2:
    .ascii "\033[1;34mdebug\033[0m\0"

    .def    main;   .scl    2;  .type   32; .endef
main:
    /* initialisation du main */
    pushq   %rbp
    movq    %rsp, %rbp
    subq    $48, %rsp
    movl    %ecx, 16(%rbp) /* int argc */
    movq    %rdx, 24(%rbp) /* char **argv */
    movq    %r8, 32(%rbp) /* char **env */

    /* saut de ligne */
    /* write init */
    movl    $1, %r8d /* write size */
    movl    $1, %ecx /* sortie standart */
    leaq    .LC0(%rip), %rdx
    /* write */
    call    write

    /* debut du code */
    movl    $-1, -8(%rbp) /* y = -1 */
    jmp .Loop_1_condition

.Loop_1_body:
    movl    $-1, -4(%rbp)
    jmp .Loop_2_condition

.Loop_2_body:
    /* affiche le charactere */
    movl    $1, %r8d
    movl    $1, %ecx
    call    write

.Loop_2_condition:
    addl    $1, -4(%rbp) /* x = -1 */
    movl    -8(%rbp), %eax        /* get y index */
    cltq
    movq    32(%rbp), %rbx        /* get envp (pointer to element 0 of char * array) */
    movq    (%rbx,%rax,8), %rdx   /* get pointer at envp+y*8
                                     pointers are 8 bytes wide */

    movl    -4(%rbp), %eax        /* get x */
    cltq
    leaq    (%rdx, %rax), %rdx    /* Get current character's address */
    cmpb    $0, (%rdx)            /* Compare current byte to char 0
                                     using cmpq will compare the next 8 bytes */
    jne .Loop_2_body

    /* saut de ligne */
    movl    $1, %r8d /* write size */
    movl    $1, %ecx /* sortie standart */
    leaq    .LC0(%rip), %rdx
    call    write

.Loop_1_condition:
    addl    $1, -8(%rbp) /* ++y */
    movl    -8(%rbp), %eax
    cltq /* passe eax en 64bits */
    movq    32(%rbp), %rbx        /* get envp (pointer to element 0 of char * array) */
    movq    (%rbx,%rax,8), %rax   /* get pointer at envp+y*8
                                     pointers are 8 bytes wide */
    cmpq    $0, %rax              /* Compare to NULL ptr */
    jne .Loop_1_body

    movl    $1, %r8d /* write size */
    movl    $1, %ecx /* sortie standart */
    leaq    .LC0(%rip), %rdx
    call    write

    /* fin du programme */
    movl    $0, %eax /* return (0) */
    addq    $48, %rsp
    popq    %rbp
    ret
    .def    write;  .scl    2;  .type   32; .endef

然后在应用程序中提供services.service1。