当我单击保存按钮时,它会触发ng-blur事件,如何触发按钮ng-click事件?如果我点击按钮或输入字段,我仍然希望触发ng-blur事件.
http://jsfiddle.net/tidelipop/wyjdT/
angular.module('MyApp', [])
.filter("placeholder", function(){
return function (text, length, end) {
//console.log(typeof text, text, length);
if(typeof text === 'undefined' || text == ''){
text = 'Click to edit...';
}
return text;
};
})
.directive("inlineEdit", function($compile, $q){
return {
restrict: "A",
replace: true,
template: function(tElement, tAttrs){
var modelStr = tAttrs.inlineEdit, optionsStr = tAttrs.options, modelXtra = '', editElStr = '';
if(tAttrs.type === 'selectbox'){
modelXtra = '.value';
editElStr = '<select ng-show="editMode" ng-blur="endEdit(\''+modelStr+'\')" ng-model="'+modelStr+'" ng-options="a.value for a in '+optionsStr+'"></select>';
}else if(tAttrs.type === 'textarea'){ …Run Code Online (Sandbox Code Playgroud) 为什么$ watch会在页面加载后直接触发,如何防止这种情况?
function MyCtrl($scope) {
// Init scope vars
$scope.data_copy = {};
// If data_copy changes...
$scope.$watch("data_copy", function(newValue, oldValue) {
alert("$watch triggered!");
}, true);
}
Run Code Online (Sandbox Code Playgroud)