zoukankan      html  css  js  c++  java
  • Angular控制器

    这里使用的是angular-1.0.1.min.js

    Angular的前端渲染

    <div>
    	<ul>
    		<li ng-repeat="i in [1,2,3]">
    			<h1>{{i}}</h1>
    		</li>
    	</ul>
    </div>
    

    效果:

    使用控制器读取JSON:

    <div ng-controller="PhoneListCtrl">
    	<ul>
    		<li ng-repeat="phone in phones">
    			<h1>{{phone.name}}</h1>
    			<p>{{phone.snippet}}</p>
    		</li>
    	</ul>
    </div>
    

    控制器代码:

    function PhoneListCtrl($scope) {
    	$scope.phones = [{
    			"name" : "Nexus S",
    			"snippet" : "Fast just got faster with Nexus S."
    		}, {
    			"name" : "Motorola XOOM with Wi-Fi",
    			"snippet" : "The Next, Next Generation tablet."
    		}, {
    			"name" : "MOTOROLA XOOM",
    			"snippet" : "The Next, Next Generation tablet."
    		}
    	];
    }
    

    效果:

    你也可以自己定义一个控制器:

    <div ng-controller="mycontroller">
    	<p>{{ article.ID }}</p>
    	<p>{{ article.Name }}</p>
    	<button ng-click="func()">测试</button>
    </div>
    

    控制器实现:

    function mycontroller($scope) {
    	$scope.article = {
    		ID : 1,
    		Name : "hell world"
    	};
    	$scope.func = function () {
    		alert(1);
    	}
    }
    

    效果:

      

      

      

      

    本文为博主原创文章,转载请在明显位置注明出处: http://www.cnblogs.com/sweng

    本作品采用知识共享署名-非商业性使用-禁止演绎 3.0 未本地化版本许可协议进行许可。

  • 相关阅读:
    数论 UVA 10943
    数论 UVA 11889
    数论 UVA 11388
    UVA 572
    hdu 1016
    poj 1308
    poj 1363
    java web-----servelet
    java IO文件读写例子(OutputStream,InputStream,Writer,Reader)
    java web环境配置类型问题
  • 原文地址:https://www.cnblogs.com/sweng/p/6371701.html
Copyright © 2011-2022 走看看