小编tid*_*pop的帖子

如何强制ng-click优先于ng-blur事件?

当我单击保存按钮时,它会触发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)

blur angularjs

38
推荐指数
2
解决办法
2万
查看次数

$ watch是在init之后直接触发的,为什么?

为什么$ watch会在页面加载后直接触发,如何防止这种情况?

http://jsfiddle.net/dcSRu/2/

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)

angularjs

31
推荐指数
1
解决办法
1万
查看次数

标签 统计

angularjs ×2

blur ×1