AngularJS 实践:应用开发 :: ENA13 价格条码-(三)

简介: 上一节我们完成了开发工作流工具和环境准备,这一节我们将进行渐进式应用编程。熟悉 AngularJS 开发的同学请跳过。 上一节参考: AngularJS 实践:应用开发 :: ENA13 价格条码-(二) 添加 web 应用所依赖的 JavaScript, Stylesheet 引用 编辑 i

上一节我们完成了开发工作流工具和环境准备,这一节我们将进行渐进式应用编程。熟悉 AngularJS 开发的同学请跳过。

上一节参考: AngularJS 实践:应用开发 :: ENA13 价格条码-(二)

获取本节代码

https://code.aliyun.com/passpile/pricebarcode

添加 web 应用所依赖的 JavaScript, Stylesheet 引用

编辑 index.html
  1. 添加 bootstrap 和 font-awesome 的 CSS 库引用
  2. 添加 angularjs 的核心 js 以及一些插件:

    angular-ui-router,angular-barcode,lodash,angular-touch(option),angular-animate(option)
    

注:如果你现在处于 gulp serve 状态,则你每一次修改后的保存,将引起浏览器自动重新加载新的内容。

[BS] Serving files from: .
[BS] Reloading Browsers...
...
<!-- build:css(../) styles/vendor.min.css -->
    <link rel="stylesheet" href="/bower_components/bootstrap/dist/css/bootstrap.css" />
    <link rel="stylesheet" href="/bower_components/font-awesome/css/font-awesome.css" />
<!-- endbuild -->
...
...
<!-- build:js(../) scripts/vendor.min.js -->
<script src="/bower_components/lodash/lodash.js"></script>
<script src="/bower_components/angular/angular.js"></script>
<script src="/bower_components/angular-touch/angular-touch.js"></script>
<script src="/bower_components/angular-animate/angular-animate.js"></script>
<script src="/bower_components/angular-ui-router/release/angular-ui-router.js"></script>
<script src="/bower_components/angular-barcode/dist/angular-barcode.js"></script>
<!-- endbuild -->

你可能会看到如下错误:
pricecode_illustration_04
这是由于我们在前一节漏掉了一个 JavaScript 的依赖库。我将使用如下命令安装遗漏的 lodash。如果你现在处于 browser sync 状态下,你可以 Ctrl + C 退出 browser sync 状态。再执行下述命令,或新打开一个 Terminal 来执行。

$ cd ~/webshop
$ bower install lodash --save

--save 参数将使我们安装的依赖库记入 ~/webshop/bower.json 文件

例如

...
"dependencies": {
  ...,
  ...,
  "lodash": "^4.6.1"
},
...

安装完成后,如果你先前停止了 browser sync ,你可以回到项目目录 cd ~/webshop/pricebarcode 通 过命令 gulp serve 开始 browser sync,这时 Chrome 会自动打开,你可检视到如下样本:
pricecode_illustration_05

Hello AngularJS

编辑 scripts/route.js 添加如下代码:
//console.log('Hi, console')
'use strict';
angular.module('pbcodeApp',[])
.controller('GreetingCtrl',function($scope){
    $scope.greeting = 'Hello AngularJS!';
});
编辑 index.html,修改并添加如下代码:
<!DOCTYPE html>
<html ng-app="pbcodeApp">
...
...
<!--h1>It's Work</h1-->
<h1 ng-controller="GreetingCtrl">{{greeting}}</h1>
...
</html>

这几处代码涉及到了 AngularJS 的 MVC, Data Binding, 模块申明 pbcodeApp, Scoping 对象的使用,还有 Expression 的使用,由于篇幅有限请自行参考学习 AngularJS 或其它相关资料

Tip: 如果你有过 ASP, JSP&Servlet 等的开发经验,这些对你来说应该很熟悉(比如:Scoping 对象就有点类似于 JSP&Servlet 的 application scope, session scope, request scope等, 并且JSP&Servlet 的 EL Expression 和 JSTL 在AngularJS也有类似概念),其差别在于一个(AngularJS)在浏览器中聚合呈现内容,另一个(ASP,JSP...)在服务器上聚合呈现内容

pricecode_illustration_06

AngularJS 实践:应用开发 :: ENA13 价格条码-(四)

目录
相关文章
|
9天前
|
域名解析 人工智能 Linux
|
19天前
|
Linux Go 开发工具
手机上跑 DeepSeek 智能体:开源安卓客户端 DSH Go 安装与使用指南
DSH Go 是一款开源安卓客户端,将 DeepSeek Harness 智能体引擎装进手机:免 Root、免 Termux,一键安装即用;支持本机运行(内置 Ubuntu+Node.js)或远程接管电脑会话;具备插话打断、过程折叠、屏幕操控、端到端加密分享等特色功能,真正实现智能体“口袋化”。
17318 63
|
17天前
|
人工智能
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
进不去 Antigravity 或 Gemini,提示所在地区不可用?三步查清 Google 账号关联地区、官方更正表单理由选法与改区注意事项。
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
|
2天前
|
人工智能 安全 网络安全
|
6天前
|
云安全 数据采集 人工智能
|
7天前
|
Linux API iOS开发
【DSH】DeepSeek Harness新手保姆教程(下载+安装+配置+使用,2026最新实测)
DeepSeek Harness(dsh)是 DeepSeek AI 开源的智能体框架,秉持“一切皆插件”理念,支持读文件、改代码、执行命令、处理表格等自动化任务;免费开源,兼容 Win/macOS,需配 API 密钥使用。(239字)
1331 3
|
14天前
|
人工智能 开发工具 开发者
2026最新codex下载安装保姆级使用教程(下载+安装+登录+使用,含所有历史版本)
Codex 是 OpenAI 推出的开源 AI 编程智能体,跑在本地终端和桌面客户端里,能读懂整个代码仓库,一句自然语言就能让它改代码、执行命令、跑测试、修 Bug,支持 Windows、macOS、Linux 三大平台。本文把 Codex下载、安装、登录、汉化、基础使用一次讲全,并整理了国内用户最常踩的坑,跟着做 10 分钟就能跑起来。
2407 7