您的位置:首页 > Web前端 > JavaScript

Angular JS 基础

2016-04-21 19:55 567 查看


restrict 约束,限制

template 模版

<script>
var myModel=angular.module("myApp",[]);
myModel.controller("helloAngular",['$scope',function($scope){
$scope.mygressting={
text:'hello'
};

}]);

//指令  hello 是自定义的标签名
myModel.directive("hello",function(){
return{
restrict:'E',
template:'<div>Hi everyOne</div>div',
replace:true
}
})
</script>


关于ng-repeat 删除

$index是传入的第几个

<body ng-app="myApp"  ng-controller="myController" >
<div>{{name}}</div>
<div ng-repeat="item in items">
<span>{{item.price}}</span>
<input type="text" ng-model="item.price"/>
<button ng-click="remove($index)">remove</button>
</div>

<script>
var app=angular.module("myApp",[]);
app.controller('myController',function($scope){
$scope.name="zhanger";
$scope.items=[
{title:'nihao',price:12345},
{title:'jeje',price:456}
];
$scope.remove=function(num){
console.log(num);
$scope.items.splice(num,1);
};
})
</script>
</body>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: