<!-- lang: html -->
<body ng-app="demo" ng-controller="DemoController">
<form name="form" >
Model value : <input type="text" size="3" ng-model="rating"><br>
Min value: <input type="text" size="3" ng-model="minRating"><br>
Max value: <input type="text" size="3"ng-model="maxRating"><br>
Form has been modified : {{ form.$dirty }}<br>
Form is valid : {{ form.$valid }}
<hr><divmin="minRating"max="maxRating"ng-model="rating"rn-stepper></div></form></body>
<!-- lang: js -->
angular.module(‘demo‘, [
‘revolunet.stepper‘
])
.controller(‘DemoController‘, function($scope) {
$scope.rating = 42;
$scope.minRating = 40;
$scope.maxRating = 50;
});
<!-- lang: js -->
// we declare a module name for our projet, and its dependencies (none)
angular.module(‘revolunet.stepper‘, [])
// declare our naïve directive
.directive(‘rnStepper‘, function() {
return {
// can be used as attribute or element
restrict: ‘AE‘,
// which markup this directive generates
template: ‘<button>-</button>‘ +
‘<div>0</div>‘ +
‘<button>+</button>‘
};
});
<!-- lang: js -->
.directive(‘rnStepper‘, function() {
return {
restrict: ‘AE‘,
// declare the directive scope as private (and empty)
scope: {},
// add behaviour to our buttons and use a variable value
template:
‘<button ng-click="decrement()">-</button>‘ +
‘<div>{{value}}</div>‘ +
‘<button ng-click="increment()">+</button>‘,
// this function is called on each rn-stepper instance initialisation
// we just declare what we need in the above template
link: function(scope, iElement, iAttrs) {
scope.value = 0;
scope.increment = function() {
scope.value++;
};
scope.decrement = function() {
scope.value--;
};
}
};
});
<!-- lang: js -->
scope: {
value: ‘=ngModel‘
}
<!-- lang: js -->
.directive(‘rnStepper‘, function() {
return {
// restrict and template attributes are the same as before.
// we don‘t need anymore to bind the value to the external ngModel
// as we require its controller and thus can access it directly
scope: {},
// the ‘require‘ property says we need a ngModel attribute in the declaration.
// this require makes a 4th argument available in the link function below
require: ‘ngModel‘,
// the ngModelController attribute is an instance of an ngModelController
// for our current ngModel.
// if we had required multiple directives in the require attribute, this 4th
// argument would give us an array of controllers.
link: function(scope, iElement, iAttrs, ngModelController) {
// we can now use our ngModelController builtin methods
// that do the heavy-lifting for us
// when model change, update our view (just update the div content)
ngModelController.$render = function() {
iElement.find(‘div‘).text(ngModelController.$viewValue);
};
// update the model then the view
function updateModel(offset) {
// call $parsers pipeline then update $modelValue
ngModelController.$setViewValue(ngModelController.$viewValue + offset);
// update the local view
ngModelController.$render();
}
// update the value when user clicks the buttons
scope.decrement = function() {
updateModel(-1);
};
scope.increment = function() {
updateModel(+1);
};
}
};
});
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有