angular+bootstrap+MVC--之一,入门
这篇直奔MVVM主题,本例实现一个bootstrap的下拉框。
展示了如下技术:
1、MVVM绑定(事件绑定,值绑定,循环绑定,循环绑定中嵌套事件并回传item),
2、angul多module,
建议在webstrom下面运行
1、HTML代码
<!doctype html> <!--suppress ALL --> <html ng-app="appTow"> <head> <script src="angular.min.js"></script> <script src="app.js"></script> <script src="./Script/jquery-2.1.1.min.js"></script> <link href="./Content/Plus/bootstrap-3.2.0-dist/css/bootstrap.min.css" rel="stylesheet"/> <script src="./Content/Plus/bootstrap-3.2.0-dist/js/bootstrap.min.js"></script> <link href="./Skin/Default/css/site.css" rel="stylesheet"/> </head> <body> <div ng-controller="MyController"> Your name: <input type="text" ng-model="username"> <button ng-click='sayHello()'>greet</button> <hr> {{greeting}} </div> <div ng-controller="MyController1"> Your name: <input type="text" ng-model="username"> <button ng-click='sayHello()'>greet</button> <li ng-repeat="x in names"> {{ x.Name}} </li> <table> <tr> <td class="ruyeeTableTDLable"><span>Names</span></td> <td class="ruyeeTableDataCell"> <div class="btn-group"> <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false"> <span>{{selectedItem}}</span><span class="caret"></span> </button> <ul class="dropdown-menu" role="menu"> <li ng-repeat="x in names"> <a href="#" ng-click="clickOneLi(x.Name)">{{ x.Name}}</a> </li> </ul> </div> </td> </tr> </table> </div> </body> </html>
2、JS代码(app.js)
angular.module('appOne', []) .controller('MyController', function ($scope) { $scope.username = 'World'; $scope.sayHello = function () { $scope.greeting = 'Hello ' + $scope.username + '!'; }; }); angular.module('appTow', ['appOne']) .controller('MyController1', function ($scope, $http) { $scope.username = 'World002'; $scope.sayHello = function () { $http.get("Data.json") .success(function (response) { $scope.names = response; }); }; $scope.clickOneLi = function (item) { $scope.selectedItem = item; } $scope.selectedItem = "Please select one"; }); var app = angular.module('myApp', []); app.controller('customersCtrl', function ($scope, $http) { $http.get("Data.json") .success(function (response) { $scope.names = response; }); });
3、Json文件(Data.json)
[ { "Name" : "Alfreds Futterkiste", "City" : "Berlin", "Country" : "Germany" }, { "Name" : "Berglunds snabbk?p", "City" : "Lule?", "Country" : "Sweden" }, { "Name" : "Centro comercial Moctezuma", "City" : "México D.F.", "Country" : "Mexico" }, { "Name" : "Ernst Handel", "City" : "Graz", "Country" : "Austria" }, { "Name" : "FISSA Fabrica Inter. Salchichas S.A.", "City" : "Madrid", "Country" : "Spain" }, { "Name" : "Galería del gastrónomo", "City" : "Barcelona", "Country" : "Spain" }, { "Name" : "Island Trading", "City" : "Cowes", "Country" : "UK" }, { "Name" : "K?niglich Essen", "City" : "Brandenburg", "Country" : "Germany" }, { "Name" : "Laughing Bacchus Wine Cellars", "City" : "Vancouver", "Country" : "Canada" }, { "Name" : "Magazzini Alimentari Riuniti", "City" : "Bergamo", "Country" : "Italy" }, { "Name" : "North/South", "City" : "London", "Country" : "UK" }, { "Name" : "Paris spécialités", "City" : "Paris", "Country" : "France" }, { "Name" : "Rattlesnake Canyon Grocery", "City" : "Albuquerque", "Country" : "USA" }, { "Name" : "Simons bistro", "City" : "K?benhavn", "Country" : "Denmark" }, { "Name" : "The Big Cheese", "City" : "Portland", "Country" : "USA" }, { "Name" : "Vaffeljernet", "City" : "?rhus", "Country" : "Denmark" }, { "Name" : "Wolski Zajazd", "City" : "Warszawa", "Country" : "Poland" } ]
angular+bootstrap+MVC--之一,入门的更多相关文章
- angular+bootstrap+MVC 之三,分页控件初级版
今天实现一个分页控件,效果如下: 1.HTML: <!doctype html> <!--suppress ALL --> <html ng-app="appT ...
- angular+bootstrap+MVC 之二,模态窗
本例实现一个bootstrap的模态窗 1.HTML代码 <!doctype html> <!--suppress ALL --> <html ng-app=" ...
- 【第三篇】ASP.NET MVC快速入门之安全策略(MVC5+EF6)
目录 [第一篇]ASP.NET MVC快速入门之数据库操作(MVC5+EF6) [第二篇]ASP.NET MVC快速入门之数据注解(MVC5+EF6) [第三篇]ASP.NET MVC快速入门之安全策 ...
- 【番外篇】ASP.NET MVC快速入门之免费jQuery控件库(MVC5+EF6)
目录 [第一篇]ASP.NET MVC快速入门之数据库操作(MVC5+EF6) [第二篇]ASP.NET MVC快速入门之数据注解(MVC5+EF6) [第三篇]ASP.NET MVC快速入门之安全策 ...
- 【第一篇】ASP.NET MVC快速入门之数据库操作(MVC5+EF6)
目录 [第一篇]ASP.NET MVC快速入门之数据库操作(MVC5+EF6) [第二篇]ASP.NET MVC快速入门之数据注解(MVC5+EF6) [第三篇]ASP.NET MVC快速入门之安全策 ...
- 带你初识Angular中MVC模型
简介 MVC是一种使用 MVC(Model View Controller 模型-视图-控制器)设计模式,该模型的理念也被许多框架所吸纳,比如,后端框架(Struts.Spring MVC等).前端框 ...
- 《疯狂前端开发讲义jQuery+Angular+Bootstrap前端开发实践》学习笔记
<疯狂前端开发讲义jQuery+Angular+Bootstrap前端开发实践>学习笔记 二〇一九年二月十三日星期三2时28分54秒 前提:本书适合有初步HTML.CSS.JavaScri ...
- 【第四篇】ASP.NET MVC快速入门之完整示例(MVC5+EF6)
目录 [第一篇]ASP.NET MVC快速入门之数据库操作(MVC5+EF6) [第二篇]ASP.NET MVC快速入门之数据注解(MVC5+EF6) [第三篇]ASP.NET MVC快速入门之安全策 ...
- 使用angular.bootstrap() 完成模块的手动加载
之前我们看到使用ng-app指令,可以实现模块的自动加载.现在我们看下,angular中如何手动加载模块.需要使用到angular.bootstrap这个函数. <html> <he ...
- Spring Mvc的入门
SpringMVC也叫Spring Web mvc,属于表现层的框架.Spring MVC是Spring框架的一部分,是在Spring3.0后发布的. Spring Web MVC是什么: Sprin ...
随机推荐
- Gradient Boost Decision Tree(GBDT)中损失函数为什么是对数形式
由于最近要经常用到XGBOOST的包,不免对相关的GBDT的原理又重新学习了一遍, 发现其中在考虑损失函数的时候,是以对数log进行度量的,囿于误差平方和函数的印象 那么为什么是对数呢?可能是下面的原 ...
- ABAP之声母韵母
我们一开始上学的时候,老师最先教的是什么? 拼音,声母,韵母,声调等等. 那么ABAP里什么是这些东西呢? 基础的数据类型,已经数据字典里的东西:域,数据元素,结构,视图,表,搜索帮助,锁... 数据 ...
- css知识点积累
关于样式的优先级问题: !important > style > [ id > class > tag ]; z-index 的属性用法: z-index属性是用来设置元素的 ...
- LaTeX自学ing
恩看标题嘛...Xs要自学LaTeX的说! 话说cnblogs不支持插入LaTeX格式的代码的说?..唔~ 嘛...首先是些简单的东西(像是文件的格式啦,作者啦之类的): (注意:\documentc ...
- jquery中的cookie操作
使用前在页面中引入下面的代码 /*! * jQuery Cookie Plugin v1.4.1 * https://github.com/carhartl/jquery-cookie * * Cop ...
- Ubuntu gmake: command not found
由于ubuntu上取消了gmake(GUNmake)的而全部使用make代替.所以此问题的解决方式是有两种: 1.makefile中 gmake用make代替: 2.创建一个make的gmake连接: ...
- ubuntu 编译oce Open CASCADE
前期准备 1 安装cmake 最新版本 sudo apt-get install cmake 2 安装OpenGl Library 和OpenGL Utilities sudo apt-get ins ...
- Get IP Address in Android 4.0+
在android2.3以下的系统中,可以使用如下的代码来获取Android系统的本地IP地址: [java] private String getLocalIPAddress() throws So ...
- PCL中point cloud的数据类型
出处: http://wiki.ros.org/pcl/Overview 1.数据类型 1.1 ROS中point cloud数据类型 sensor mesgs::PointCloud sensor ...
- sqlserver查看被锁表、解锁
查看别锁表 select request_session_id spid,OBJECT_NAME(resource_associated_entity_id) tableName from sys.d ...