angular.js - How to introduce other js files in angularjs
習慣沉默
習慣沉默 2017-05-15 16:56:02
0
3
1024

I want to introduce other js files into angularjs. Here I want to introduce the image carousel plug-in in sister ui, which has similar needs. Usually this requires embedding js in the page
For example, something like this, if you introduce the js plug-in directly into the html, and then write it like this in the page, it will have no effect, and this requires jQuery, although I am in angular jQuery is not used... How should I configure angular?

$(function() {
  $('.am-slider').flexslider({
    // options
  });
});
習慣沉默
習慣沉默

reply all(3)
我想大声告诉你

1. Load everything in HTML at once
2. Use the oclazyload plug-in
3. Use angular’s ​​$q to write a file loading service

小葫芦

Using https://github.com/revolunet/angular-carousel can meet your requirements

阿神

It’s a question and answer for myself. Currently, requirejs is used to solve the dependency problems in the project.
Firstmain.js is the entrance to the entire ng application. Here is where you add the plug-ins to be loaded

'use strict';

require.config({
    baseUrl: 'js',
    waitSeconds: 0,
    paths: {
        text: '../lib/require/text',
        jquery: '../lib/jquery/dist/jquery',
        angular: '../lib/angular/angular',
        bootstrap: '../lib/bootstrap/dist/js/bootstrap',
        bindonce: '../lib/angular-bindonce/bindonce.min',
        ngtable: '../lib/ng-table/dist/ng-table',
        ngBootstrap: '../lib/angular-bootstrap/ui-bootstrap',
        ngBootstrapTpls: '../lib/angular-bootstrap/ui-bootstrap-tpls',
        uiRoute: '../lib/angular-ui-router/release/angular-ui-router',
        oclazyload: '../lib/oclazyload/dist/ocLazyLoad',
        datePicker: '../lib/angularjs-datetime-picker/angularjs-datetime-picker',
        app: 'app',
        common: 'common',
        host:'../host',
    },
    shim: {
        'angular': {
            exports: 'angular'
        },
        'bootstrap':{
            deps:['jquery']
        },
        'bindonce': {
            deps: ['angular']
        },
        'ngtable': {
            deps: ['angular']
        },
        'ngBootstrap': {
            deps: ['angular']
        },
        'ngBootstrapTpls': {
            deps: ['ngBootstrap', 'angular']
        },
        'uiRoute': {
            deps: ['angular']
        },
        'oclazyload': {
            deps: ['angular']
        },
        'datePicker': {
            deps: ['angular']
        },
        'myDatePicker': {
            deps: ['jquery']
        }
    },
    priority: [
        'angular'
    ]
});

require([
    'angular',
    'jquery',
    'app',
    'routes',
    'bootstrap',
], function(angular) {
    $(document).ready(function() {
        var appName = $('body').attr('data-ngApp');
        angular.bootstrap(document, [appName]); //手动启动ng应用
    });
});

When using app.js, the index.html page has a controller to start the application

define(['angular',
        'bindonce',
        'ngBootstrap',
        'ngBootstrapTpls',
        'ngtable',
        'uiRoute',
        'oclazyload',
        'datePicker',
          ],
    function(angular) {
    var myApp = angular.module('myApp', ['pasvaz.bindonce', 'ngTable', 'ui.bootstrap', 'ui.router', 'oc.lazyLoad','angularjs-datetime-picker']);
    myApp.controller('admin', ['$scope','$timeout', function($scope, $timeout) {
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template