As the title suggests... I'm facing a challenge with this code snippet:
(function(angular) {
'use strict';
angular.module('app', [])
.controller('ctrl', ['$scope', function($scope) {
$scope.init = function() {
$scope.response = "press the button";
}();
$scope.data = {
availableOptions: [{
id: '1',
name: 'num'
}],
selectedOption: {
name: 'selected field'
}
};
$scope.data2 = {
availableOptions2: [{
id: '0',
name: 'null'
}
],
selectedOption2: {
name: 'null'
}
};
$scope.search = function() {
$scope.response = "you pressed a button \\o/";
alert($scope.response);
};
$scope.request = function(req) {
$http(req).then(function() { /*successCallback*/ },
function() { /*errorCallback*/ });
};
}]);
})(window.angular);
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<script src="//code.angularjs.org/1.7.3/angular.min.js"></script>
<script src="analyzer.js"></script>
</head>
<body ng-app="app">
<div ng-controller="ctrl" ng-show="true">
<!--class="ng-hide" is automatically added when ng-show="false"-->
<!--SEARCH-->
<form name="myForm">
<label for="mySelect">Select a field:</label>
<select name="mySelect" id="mySelect" ng-options="option.name for option in data.availableOptions track by option.id" ng-model="data.selectedOption"></select>
<br/>
<div style="color:#757575">
<input ng-model="query" type="text" size=45 class="form-control" placeholder="Search your {{data.selectedOption.name}} here..." />
<div ng-show="true">
or directly select your choice here...
<select name="subSelect" id="subSelect" ng-options="option.name for option in data2.availableOptions2
track by option.id" ng-model="data2.selectedOption2"></select>
<br/>
<button style="color:#757575" ng-click="search()">
...and go!</button>
</div>
</div>
</form>
<!--RESPONSE-->
<div ng-controller="ctrl" ng-show="true">
<p>{{response}}</p>
</div>
</div>
</body>
</html>
Despite attempting various solutions, the view does not update when modifying $scope.response
in this example... and alert($scope.response)
confirms that the button functionality is intact... Utilizing methods like $interval, $timeout, $apply, $watch have proved unsuccessful in resolving the issue. Any insights would be greatly appreciated.
Thank you for your assistance.
If this query has been previously addressed, I apologize as I couldn't locate a resolution.