私が達成しようとしているのは、入力フィールドに追加のインターフェイスを追加して、+ ボタンと - ボタンをクリックして数値を増減できるようにすることです。
(本質的には、input[type=number] フィールドが chrome で持っているものですが、これをクロス ブラウザーと互換性があり、すべてのブラウザーでプレゼンテーションを完全に制御できるようにしたいと考えています)。
ビュー内のコード:
<input data-ng-model="session.amountChosen" type="text" min="1" class="form-control input-small" data-number-input>
指令コード:
app.directive('numberInput', function() {
return {
    require: 'ngModel',
    scope: true,
    link: function(scope, elm, attrs, ctrl) {
        var currValue = parseInt(scope.$eval(attrs.ngModel)),
            minValue = attrs.min || 0,
            maxValue = attrs.max || Infinity,
            newValue;
        //puts a wrap around the input and adds + and - buttons
        elm.wrap('<div class="number-input-wrap"></div>').parent().append('<div class="number-input-controls"><a href="#" class="btn btn-xs btn-pluimen">+</a><a href="#" class="btn btn-xs btn-pluimen">-</a></div>');
        //finds the buttons ands binds a click event to them where the model increase/decrease should happen
        elm.parent().find('a').bind('click',function(e){
            if(this.text=='+' && currValue<maxValue) {
                newValue = currValue+1;    
            } else if (this.text=='-' && currValue>minValue) {
                newValue = currValue-1;    
            }
            scope.$apply(function(){
                scope.ngModel = newValue;
            });
            e.preventDefault();
        });
    }
  };
}))
これは、scope.$eval(attrs.ngModel) を介して現在のモデル値を取得できますが、新しい値の設定に失敗します。
編集後: これは現在動作するコードです (この問題の解決策を見たくない場合)
app.directive('numberInput', function() {
  return {
    require: 'ngModel',
    scope: true,
    link: function(scope, elm, attrs, ctrl) {
        var minValue = attrs.min || 0,
            maxValue = attrs.max || Infinity;
        elm.wrap('<div class="number-input-wrap"></div>').parent().append('<div class="number-input-controls"><a href="#" class="btn btn-xs btn-pluimen">+</a><a href="#" class="btn btn-xs btn-pluimen">-</a></div>');
        elm.parent().find('a').bind('click',function(e){
            var currValue = parseInt(scope.$eval(attrs.ngModel)),
                newValue = currValue;
            if(this.text=='+' && currValue<maxValue) {
                newValue = currValue+1;    
            } else if (this.text=='-' && currValue>minValue) {
                newValue = currValue-1;    
            }
            scope.$eval(attrs.ngModel + "=" + newValue);
            scope.$apply();            
            e.preventDefault();
        });
    }
  };
})