<body ng-app="myApp" ng-controller="myCtrl">
<test-directive></test-directive>
<script>
angular.module("myApp",[])
.controller("myCtrl",function($scope){
$scope.data = {
name:"白衣如花"
};
})
.directive("testDirective",function(){
return {
restrict:"E",
template:"<h1>{{data.name||'未定义'}}</h1>"
}
});
</script>
</body>
<body ng-app="myApp" ng-controller="myCtrl">
<test-directive></test-directive>
<script>
angular.module("myApp",[])
.controller("myCtrl",function($scope){
$scope.data = {
name:"白衣如花"
};
})
.directive("testDirective",function(){
return {
restrict:"E",
scope: {},
template:"<h1>{{data.name||'未定义'}}</h1>"
}
});
</script>
</body>
<body ng-app="myApp" ng-controller="myCtrl">
<p>名字:{{outerName}}</p>
<test-directive inner-name="outerName"></test-directive>
<script>
angular.module("myApp",[])
.controller("myCtrl",function($scope){
})
.directive("testDirective",function(){
return {
restrict:"E",
scope: {
innerName: "="
},
template:"<input type='text' ng-model='innerName' placeholder='白衣如花'>"
}
});
</script>
</body>
<test-directive name="outerName"></test-directive>
scope: {
innerName: "=name"
},
<body ng-app="myApp" ng-controller="myCtrl">
<input type='text' ng-model='outerName' placeholder='白衣如花'>
<test-directive inner-name="{{outerName}}"></test-directive>
<script>
angular.module("myApp",[])
.controller("myCtrl",function($scope){
})
.directive("testDirective",function(){
return {
restrict:"E",
scope: {
innerName: "@"
},
template:"<p>名字:{{innerName}}</p>" +
"<button ng-click='innerName=innerName+1'>点击</button>"
}
});
</script>
</body>
<body ng-app="myApp" ng-controller="myCtrl">
<p>名字:{{outerName}}</p>
<test-directive on-click="click(name)"></test-directive>
<script>
angular.module("myApp",[])
.controller("myCtrl",function($scope){
$scope.click = function (name) {
$scope.outerName = name || "白衣如花";
}
})
.directive("testDirective",function(){
return {
restrict:"E",
scope: {
onClick: "&"
},
template:"<input type='text' ng-model='innerName' placeholder='白衣如花'>" +
"<button ng-click='onClick({name: innerName})'>点击</button>"
}
});
</script>
</body>
<body ng-app="myApp" ng-controller="myCtrl">
<button ng-click="click()">重置</button>
<test-directive action="action"></test-directive>
<script>
angular.module("myApp",[])
.controller("myCtrl",function($scope){
$scope.action = {};
$scope.click = function () {
$scope.action.reset();
}
})
.directive("testDirective",function(){
return {
restrict:"E",
scope: {
action: "="
},
template:"<input type='text' ng-model='name' placeholder='白衣如花'>",
controller: function ($scope) {
$scope.action.reset = function () {
$scope.name = "白衣如花"
}
}
}
});
</script>
</body>
<body ng-app="myApp" ng-controller="myCtrl">
<test-directive action="action"></test-directive>
<script>
angular.module("myApp",[])
.controller("myCtrl",function($scope){
$scope.action = {};
$scope.action.init();
})
.directive("testDirective",function(){
return {
restrict:"E",
scope: {
action: "="
},
template:"<input type='text' ng-model='name' placeholder='白衣如花'>",
controller: function ($scope) {
$scope.action.init = function () {
$scope.name = "白衣如花"
}
}
}
});
</script>
</body>
<body ng-app="myApp" ng-controller="myCtrl">
<test-directive action="action"></test-directive>
<script>
angular.module("myApp",[])
.controller("myCtrl",function($scope){
$scope.action = {name: "白衣如花"};
})
.directive("testDirective",function(){
return {
restrict:"E",
scope: {
action: "="
},
template:"<input type='text' ng-model='name' placeholder='白衣如花'>",
link: function (scope, elem, attrs) {
scope.$watch(attrs.action, function (value) {
scope.action.init();
})
},
controller: function ($scope) {
$scope.action.init = function () {
$scope.name = $scope.action.name
}
}
}
});
</script>
</body>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有