html - how do I retrieve an input variable onto a javascript controller in angular? -
i have search input field , trying send input javascript variable i'd use. in angular
input
<input ng-model="searchtext" placeholder="search">
controller.js
angular.module('searchkingapp') .controller('mainctrl', function($scope){ //which code can put under here? //and end having var searcheditem = //the string have searched for..
i have javascript file located in different place html file.
thanks alot in advance.
you this.
var app = angular.module("sampleapp", []); app.controller("samplecontroller", ["$scope", function($scope) { $scope.searchtext = "hello"; $scope.search = function() { console.log($scope.searchtext); } } ]);
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.min.js"></script> <div ng-app="sampleapp"> <div ng-controller="samplecontroller"> <input ng-model="searchtext" /> <button ng-click="search()">search</button> </div> </div>
Comments
Post a Comment