码迷,mamicode.com
首页 > 其他好文 > 详细

Angular 简单使用

时间:2015-09-05 19:25:10      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:angularjs 工具

简单示例,直接上代码

1、Hello World


<!DOCTYPE html>
<html ng-app="helloworld">
<head>
    <title>Angular JS (一)Hello World</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
    <link rel="stylesheet" href="/angularjs/css/bootstrap-3.0.0/css/bootstrap.css">
    <script type="text/javascript" src="/angularjs/angular.min.js"></script>
    <script type="text/javascript" src="/angularjs/demo/HelloWorld/helloworld.js"></script>
</head>
<body ng-controller="helloworldCtrl">
    <P>{{helloworld}}</P>
</body>
</html>
var helloworld = angular.module("helloworld", []);
//helloworld.controller("helloworldCtrl", function($scope){  可以不要‘$scope‘参数
helloworld.controller("helloworldCtrl", [‘$scope‘, function($scope){
    $scope.helloworld = "Hello World";
}]);


运行:

技术分享

到这里一个完整HelloWorld示例就结束了。

其实这里是存在一个问题的,当我们在刷新比较快,或者把 加载的angularJS去掉就会显示

{{helloworld}}

这对于页面显示来说是很不友好的,那么怎么解决呢?这里就需要用到指令,我们在解释指令的时候在具体的解释说明


2、一般的项目目录结构

技术分享

在项目下面,一般情况是:css、img、src、js、tpl以及入口文件 index.html 

如果我们需要代码混淆工具、自动化测试等需要安装基于nodeJS的工具,一般是安装在 node_modules目录下面,如果需要测试,那么还会有 test 文件夹。

通过 nmp 安装这些辅助工具

1、Karma:  单元测试工具。配合jasmine使用   karma-coverage 覆盖率

2、Jasmine : 提供一套语法用来编写测试用例                      

3、grunt :  JS 文件合并,JS 代码压缩   www.grunt.org  到官网上查看gruntfilt示例,安装必要的插件

                grunt-contrib-ugify   代码混淆     

                grunt-contrib-concat   文件合并

                grunt-contrib-watch    监控文件变化

4、Bower :  依赖管理工具 .  自动安装依赖组件,依赖组件监控,版本控制  http://bower.io

5、Batarang:angularJS调试的工具(chrom)

6、http-server:简单的http服务 

7、protractor:专门为 AngularJS定制的测试工具  。基于 webDriverJS

    原理:利用webDriverJs,借助NodeJS直接调用浏览器的接口


本文出自 “追梦” 博客,请务必保留此出处http://dreameng.blog.51cto.com/1187899/1691598

Angular 简单使用

标签:angularjs 工具

原文地址:http://dreameng.blog.51cto.com/1187899/1691598

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!