I'm facing an issue while trying to pre-fill a value in an input field on a page. Although the page loads with the value, it doesn't trigger any filtering until I manually enter something. Is there a way to make the filtered results load automatically when the page loads?
As a newbie to Angular JS, I would really appreciate any guidance or assistance in the right direction.
So far, I have attempted:
Adding
ng-init="search.keywords='initial'"
to the input tag, but it didn't result in any filtering.
Also, using
$scope.search = { keywords: 'initial' };
did set the initial value, but again, no filtering occurred.
<input type="text" id="search-keywords" ng-model="search.keywords"
class="form-control" placeholder="Keyword search">
$scope.$watch("search", function (newVal, oldVal) {
if (newVal) {
$scope.doFilter(newVal);
}
}, true);
$scope.doFilter = function (search) {
// Filtering logic here
};
$scope.filterByKeywords = function (courses, keywords) {
// Keyword filtering logic here
};
Your help in resolving this issue would be highly appreciated!