#目录 [TOC] #1. 概述html
angularjs-1.5加入了许多新特性,我最感兴趣的是如下两个:java
顺便介绍一些angular经常使用的一些插件jquery
-lib/jquery/jquery-1.8.0.min.js -lib/angular/angular.min.js -lib/angular/angular-route.min.js -lib/requireJS/require.js -scripts/inject.js -scripts/test.js -scripts/app.js -main.js -index.html -pages/app.html -pages/home.html -pages/index.html
/** * require 主入口,相关配置依赖从这里配置 */ require.config({ baseUrl: "/", //每次新加载js,为了不缓存 urlArgs: "bust=" + (new Date()).getTime(), paths: { 'jquery': 'lib/jquery/jquery-1.8.0.min', 'angular': 'lib/angular/angular.min', 'angular-route': 'lib/angular/angular-route.min', 'app': 'scripts/app', //入口注入脚本 'inject' : 'scripts/inject' }, shim: { 'angular': ['jquery'], 'angular-route': ['angular'] } }); require(["inject"], function() {});
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <script data-main="main" src="lib/requireJS/require.js"></script> <title>angularJs & requireJs</title> </head> <body> <!--程序入口--> <app/> </body> </html>
##注入脚本(inject.js)git
!(function () { 'use strict'; //固然了这个scripts的数据彻底能够从服务器上动态获取回来加载 var scripts = ['scripts/test']; //依赖脚本加载 require(scripts, function () { //渲染 angular.bootstrap(document, ['app']); }); }());
这里是对主模块的基本定义,最后必须返回模块的对象,用于进行依赖而后进行下一步的处理程序员
define("app",["angular",'angular-route'], function(a, r) { var app = angular.module('app', ['ngRoute']) .controller("IndexCtrl",["$scope", function($scope) { $scope.name = "王五"; }]) .component('app', { templateUrl: "pages/app.html" }) .config(["$routeProvider", function($routeProvider) { $routeProvider. when("/home", { templateUrl: "pages/home.html", resolve : { $routeChangeSuccess : function($rootScope) { $rootScope.appName = '这里是appName'; } } }). when("/index", { templateUrl: "pages/index.html", controller: "IndexCtrl" })]); return app; });
<h2>头部</h2> 内容: <java></java> <div ng-view></div> <h2>底部</h2>
//这里必须依赖app脚本 define(["app"], function (app) { //定义java组件 app.component('java', { template: "我是java程序员", }); });
这里是home.html
#结果angularjs
http://localhost:8080/app.html#/homegithub
html展现: dom结果:
bootstrap