AngularJs是为了克服Html在构建应用上的不足而设计的。Html是一门很好的为静态文件展示设计的声明式语言,但是要构建web应用的话就显得乏力了。所以我做了一些工作来让浏览器做我瞎向要的事。

很久没有写过东西了,感觉写东西都不知道从哪里开始了,还是先写点技术性的吧,angularJs--我喜欢把它叫做“俺哥啦Js”

1.简单介绍使用ng-app

决定了angularJs的作用域范围,你可以如下使用

  代码如下:

  <html ng-app>

  ....

  </html>

来让angularjs渲染整个页面,你也可以使用

  代码如下:

  <div ng-app="myapp">

  ...

  </div>

来渲染其中的一部分。

2.ng-model

  ng-model,当你的数据模型被改变的时候,譬如ng-model="test",其中这个test的数值被改变的时候,{{test}}的值也将跟随改变,也就是连接到ng-model中的test也跟随改变,如下

  代码如下:

  <!doctype html>

  <html>

    <head>

      <script src="angular.min.js" ></script>

      <title>learing argularJs</title>

    </head>

    <body ng-app>

    <input ng-model='test'>{{test}}

    </body>

  </html>

3.angular.module

这个主要做模板的注册,创建和索引,譬如我们ng-app想把这个注册成为一个服务就要用,当我们引用索引一个模块的时候也要使用

  代码如下:

  angular.module(name,[requires],[configFn]);

  #name 类型string创建的名称,自己定义

  #require 简单理解就是你需要包含的使用木块,譬如ngRoute路由模块

  #configFn 可以选配的功能模块,功能和module.config类似

4.controller

controlller英文是控制器,是angular.Module的方法controller(name,constructor);其中那么是controller的名字,constructor是控制器构造函数,我们利用一段代码来来说明

  代码如下:

  <!doctype html>

  <html>

    <head>

      <script src="angular.min.js"><script>

      <script type="text/javascript">

      var app=angular.module("myapp",[]);

      app.controller("mytest",function($scope){

        $scope.test="你好,张强"

});

      </script>

      <title>learning angularjs</title>

    </head>

    <body ng-app="myapp" ng-controller="mytest">

      <input ng-model='test'>{{test}}

    </body>

   </html>

5.value

  value也是angular.model中的方法value(name,object);其中那么是service的名称,object是服务器实例对象,这个时候我们可以把上面的代码修改成这样:

  代码如下:

<!doctype html>

<html>

<head>

<script src="angular.min.js" type="text/javascript"></script>

<script type="text/javascript">

var app = angular.module('myapp',[])

.value('testvalue','word');

app.controller('mytest',function($scope,testvalue){

$scope.test="hello "+ testvalue;

});

</script>

<title>learing argularjs--widuu</title>

</head>

<body ng-app='myapp' ng-controller='mytest' >

<input ng-model='test'>{{test}}

</body>

</html>

5.factory

factory也是angular.Module中的方法factory(name, providerFunction);;其中name是service的名称,providerFunction是函数用于创建新的服务器对象,这个时候我们就可以把上边的代码修改正成这样

<!doctype html>

<html>

<head>

<script src="angular.min.js" type="text/javascript"></script>

<script type="text/javascript">

var app = angular.module('myapp',[])

.value('testvalue','widuu')

.factory('testfactory',function(testvalue){

return{

lable:function(){

return "this can output : hello "+ testvalue;

}

}

});

app.controller('mytest',function($scope,testvalue,testfactory){

$scope.test = "hello "+ testvalue;

$scope.output = testfactory.lable();

});

</script>

<title>learing argularjs--widuu</title>

</head>

<body ng-app='myapp' ng-controller='mytest' >

<input ng-model='test'>{{test}}

{{output}}

</body>

</html>

6.provider

provider也是angular.Module中的方法provider(name, providerType);其中name是service的名称,providerFunction是函数用于创建新的服务器对象,这个跟factory差不多,我们现在用provider重写

<!doctype html>

<html>

<head>

<script src="angular.min.js" type="text/javascript"></script>

<script type="text/javascript">

var app = angular.module('myapp',[])

.value('testvalue','widuu')

.provider('testprovider',

function(){

this.lable = "this will output : hello widuu";

this.$get = function () {

return this;

}

}

);

app.controller('mytest',function($scope,testvalue,testprovider){

$scope.test = "hello "+ testvalue;

$scope.output = testprovider.lable;

});

</script>

<title>learing argularjs--widuu</title>

</head>

<body ng-app='myapp' ng-controller='mytest' >

<input ng-model='test'>{{test}}

{{output}}

</body>

</html>

7.service

service也是angular.Module中的方法service(name, constructor);其中name是service的名称,constructor一个将被实例化的构造函数,这个跟factory差不多,我们现在用service重写

<!doctype html>

<html>

<head>

<script src="angular.min.js" type="text/javascript"></script>

<script type="text/javascript">

var app = angular.module('myapp',[])

.value('testvalue','widuu')

.service('testservice',

function(testvalue){

this.lable = function(){

return "this will output:hello "+testvalue;

}

}

);

app.controller('mytest',function($scope,testvalue,testservice){

$scope.test = "hello "+ testvalue;

$scope.output = testservice.lable();

});

</script>

<title>learing argularjs--widuu</title>

</head>

<body ng-app='myapp' ng-controller='mytest' >

<input ng-model='test'>{{test}}

{{output}}

</body>

</html>

8.constant

constant也是angular.Module中的方法constant(name, object);其中name是常量的名称,而object是常量的值,我们可以这样写的

<!doctype html>

<html>

<head>

<script src="angular.min.js" type="text/javascript"></script>

<script type="text/javascript">

var app = angular.module('myapp',[])

.value('testvalue','widuu')

.constant('count',23)

.service('testservice',

function(testvalue,count){

this.lable = function(){

return "this will output:hello "+testvalue+",age is "+count;

}

}

);

app.controller('mytest',function($scope,testvalue,testservice){

$scope.test = "hello "+ testvalue;

$scope.output = testservice.lable();

});

</script>

<title>learing argularjs--widuu</title>

</head>

<body ng-app='myapp' ng-controller='mytest' >

<input ng-model='test'>{{test}}

{{output}}

</body>

</html>

今天就先写到这里。拜拜

angularJs基础的更多相关文章

  1. AngularJS基础入门初探

    一.AngularJS简介 1.1 什么是AngularJS (1)一款非常优秀的前端JS框架,可以方便实现MVC/MVVM模式 (2)由Misko Hevery 等人创建,2009年被Google所 ...

  2. AngularJS基础知识1

    一.angularJS简介 1.什么是 AngularJS? AngularJS 是一个 JavaScript 框架.它是一个以 JavaScript 编写的库.AngularJS是协助搭建单页面工程 ...

  3. AngularJS基础概念

    作用域.控制器.指令 作用域 应用的作用域是和应用的数据模型相关联的,同时作用域也是表达式执行的上下文.$scope对象是定义应用业务逻辑.控制器方法和视图属性的地方. 作用域是应用状态的基础.基于动 ...

  4. AngularJs基础总结(1.4版本)

    注明:现在用的是最新的1系列1.4版本. 一.细节方面入手: 1,ng-app根节点,一般别写在html上面,最多也就写在body就行了,因为我们难免会忘记这个写在哪里,然后复制一些案例代码却总报错. ...

  5. Angularjs基础教程

    Angularjs-基础教程 一些angualr的基础概念,适合入门. 1.下载 推荐 bower 或 npm 安装. bower install angular bower install angu ...

  6. AngularJS基础总结

    w3shools    angularjs教程  wiki   <AngularJS权威教程> Introduction AngularJS is a JavaScript framewo ...

  7. Angularjs基础(学习整理)

    AngularJS 通过 ng-directives 扩展了 HTML. ng-app 指令定义一个 AngularJS 应用程序. ng-model 指令把元素值(比如输入域的值)绑定到应用程序. ...

  8. 3天学习完AngularJS基础内容小结

    简介:AngularJS 是一个 JavaScript 框架.它是一个以 JavaScript 编写的库. 一.AngularJS大致功能模块 二.页面交互变得简单 1.示例:计算价格 <htm ...

  9. 一步一步弄懂angularJS基础

    问题1:ng-app指令的使用以及自定义指令 <!doctype html> <!--这里的ng-app的属性值就是模块的名称,也就是 angular.module("My ...

  10. AngularJS基础知识2

    一.angularJS双向数据绑定 利用双向数据绑定,不仅能把数据模型的变化同步到视图上面,还可以利用双向数据绑定的特性来做一些样式上面的控制. 双向数据绑定用处很多,不仅仅是像知识点1中的那个例子, ...

随机推荐

  1. 快速开发一个PHP电影爬虫

    今天来做一个PHP电影小爬虫.我们来利用simple_html_dom的采集数据实例,这是一个PHP的库,上手很容易.simple_html_dom 可以很好的帮助我们利用php解析html文档.通过 ...

  2. 多个Python环境的构建:基于virtualenv 包

    假如一台计算中安装多个Python版本,而不同版本可能会pip安装不同的包,为了避免混乱,可以使用virtualenv包隔离各个Python环境,实现一个Python版本对应一套开发环境. 本地概况: ...

  3. ylbtech-Miscellaneos

    ylbtech-Miscellaneos: A,返回顶部 1, 2, B返回顶部 1, 2 作者:ylbtech出处:http://ylbtech.cnblogs.com/本文版权归作者和博客园共有, ...

  4. Stanford NLP学习笔记1:课程介绍

    Stanford NLP课程简介 1. NLP应用例子 问答系统: IBM Watson 信息提取(information extraction) 情感分析 机器翻译 2. NLP应用当前进展 很成熟 ...

  5. [转]Dynamic SQL & Stored Procedure Usage in T-SQL

    转自:http://www.sqlusa.com/bestpractices/training/scripts/dynamicsql/ Dynamic SQL & Stored Procedu ...

  6. 转 @html.ActionLink的几种参数格式

    一 Html.ActionLink("linkText","actionName") 该重载的第一个参数是该链接要显示的文字,第二个参数是对应的控制器的方法, ...

  7. 用svg制作loading动画

    首先说明:由于各浏览器对svg动画事件支持不统一,此loading动画在Firefox,Opera,Chrome中均没有问题,IE和Safari中有问题,可能是不支持SIML写动画的语法, 但是用Ca ...

  8. Django RedirectView

    RedirectView作用是重定向一个指定,给定的Url.这个给定的Url可能包含有字典风格的字符串,因为关键字(词)会被改变,所以从这个Url中捕获的参数可能也会被修改,例如,Url中的“%”应该 ...

  9. 区分LocalStorage和偏好数据

    偏好数据类似于web.config或者session,cookie之类的值,一般用于保存一些状态值,不推荐大量的数据通过此方式存储 Local Storage不仅可以寸字符串,还可以寸JSON对象

  10. JQuery 在循环中设置事件,最后一个覆盖了前面所有的设置

    function setValidation() {         for (i = 0; i < alValidations.length; i++) { //alValidations是一 ...