HTML濾波器輸入與指令
<input type="text" name="usernr" ng-model="userNr" placeholder="user nr"
tabindex="2" ng-usernumber/>
的JavaScript
app.directive('ngUserNumber', function() {
return {
restrict: 'A',
require: 'ngModel',
link: function(scope, elm, attrs, ctrl) {
console.log("inside directive");
ctrl.$parsers.push(function(data) {
console.log("//convert data from view format to model format");
data = data.toString() + " test";
return data; //converted
});
ctrl.$formatters.push(function(data) {
console.log("//convert data from model format to view format");
data = data.toString() + " test";
return data; //converted
});
}
};
});
我想從裏面指令取代伍模型提供的數據,與數據。但沒有任何反應。如何不使用自定義指令?
我跟着這個文檔:http://www.ng-newsletter.com/posts/directives.html
其它來源:https://stackoverflow.com/a/15346236/489856
鏈接函數是否被調用\執行? – Chandermani
否(日誌未執行) – Vincent
您在html中的指令名應該是'mg-user-number' – Chandermani