Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: (untagged)
i have html page on this page i want to pass the value of ng-model as a parameter to ng-mousedown :-
<ng-model ng-mousedown="check(ctrl.selectedPeople)">


And i have an js file with respect to html file where i write angular code in this file i have a function that is CHECK(searchtext) , i want to call it on mousedown event but i getting searchtext parameter as undefined ,

JavaScript
/// <reference path="library/angular.js" />


'use strict';

var app = angular.module('demo', ['ngSanitize', 'ui.select']);
app.filter('propsFilter', function () {
 
    return function (items, props) {
        var out = [];

        if (angular.isArray(items)) {
            var keys = Object.keys(props);

            items.forEach(function (item) {
              var itemMatches = false;
                  //itemMatches = true;// when data will populate from database.
                for (var i = 0; i < keys.length; i++) {
                    var prop = keys[i];
                    var text = props[prop].toLowerCase();
                    if (item[prop].toString().toLowerCase().indexOf(text) !== -1) {
                     //  itemMatches = false;
                         itemMatches = true;// when data will populate from database.

                        break;
                    }
                }
              
                if (itemMatches) {
                    out.push(item);
                }
            });
        } else {

            out = items;
        }

        return out;
    };
});

app.controller('DemoCtrl', function ($scope) {
  
    var result = this;
    result.tagTransform = function (newTag) {

        var item = {
            name: newTag


        };

        return item;
    };
    //var str = "January,February,March,April,May,June,July,August,September,October singh";
    //var splittedString = str.split(',');
    var arr = [];
    //splittedString.forEach(function (v) {
    //    arr.push({ name: v });
    //});

    var arr = [
        {
           
            "name": "TCS",
            "Access": "TATA"

        },
        {
          
            "name": "GG",
            "Access": "GOOGLE"

        },

        {
           
            "name": "MS",
            "Access": "Micosoft"

        }
    ];
    result.people = arr;
    result.colors = ['Blue', 'Red'];
    result.selectedPeople2 = result.selectedPeople;

    $scope.check = function (searchText) {
        debugger;
        var Forsecond="";
          var ff = searchText[0];
          var dd = ff.name;
          if(dd==ff.name)
          {
              Forsecond= ff.Access;
          }
          return Forsecond;
   
    }
});


What I have tried:

i have html page on this page i want to pass the value of ng-model as a parameter to ng-mousedown :-
<ng-model ng-mousedown="check(ctrl.selectedPeople)">


And i have an js file with respect to html file where i write angular code in this file i have a function that is CHECK(searchtext) , i want to call it on mousedown event but i getting searchtext parameter as undefined ,

JavaScript
/// <reference path="library/angular.js" />


'use strict';

var app = angular.module('demo', ['ngSanitize', 'ui.select']);
app.filter('propsFilter', function () {
 
    return function (items, props) {
        var out = [];

        if (angular.isArray(items)) {
            var keys = Object.keys(props);

            items.forEach(function (item) {
              var itemMatches = false;
                  //itemMatches = true;// when data will populate from database.
                for (var i = 0; i < keys.length; i++) {
                    var prop = keys[i];
                    var text = props[prop].toLowerCase();
                    if (item[prop].toString().toLowerCase().indexOf(text) !== -1) {
                     //  itemMatches = false;
                         itemMatches = true;// when data will populate from database.

                        break;
                    }
                }
              
                if (itemMatches) {
                    out.push(item);
                }
            });
        } else {

            out = items;
        }

        return out;
    };
});

app.controller('DemoCtrl', function ($scope) {
  
    var result = this;
    result.tagTransform = function (newTag) {

        var item = {
            name: newTag


        };

        return item;
    };
    //var str = "January,February,March,April,May,June,July,August,September,October singh";
    //var splittedString = str.split(',');
    var arr = [];
    //splittedString.forEach(function (v) {
    //    arr.push({ name: v });
    //});

    var arr = [
        {
           
            "name": "TCS",
            "Access": "TATA"

        },
        {
          
            "name": "GG",
            "Access": "GOOGLE"

        },

        {
           
            "name": "MS",
            "Access": "Micosoft"

        }
    ];
    result.people = arr;
    result.colors = ['Blue', 'Red'];
    result.selectedPeople2 = result.selectedPeople;

    $scope.check = function (searchText) {
        debugger;
        var Forsecond="";
          var ff = searchText[0];
          var dd = ff.name;
          if(dd==ff.name)
          {
              Forsecond= ff.Access;
          }
          return Forsecond;
   
    }
});
Posted
Updated 5-Jul-16 20:46pm
v2

1 solution

try like this

HTML
<html>
<head>
    <title></title>    
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> 
    <script>
        var app = angular.module('myapp', []);
        app.controller('myctrl', myfun);
        function myfun($scope) {
            $scope.myTextValue = 'This is textbox';
           
            $scope.check = function (model) { 
                alert(model.myTextValue);// or   alert($scope.myTextValue);
            }
        }
    </script>
</head>

<body ng-controller="myctrl" ng-app="myapp">
    <input type="text" ng-model="myTextValue" ng-mousedown="check(this)" />     
</body>
</html>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900