-1

I am learning how to use angularjs and just need a good place to start. I tried to write this simple app but cant get it working, so can someone help me fix it, and help point me in the right direction.

<!DOCTYPE html>
<html>
<script 
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js">
</script>
<body>

<div ng-app="myApp" ng-controller="myCtrl">
    Name: <input ng-model="palcheck">
    <h1>{{palcheck}}</h1>
</div>

<script>
   var app = angular.module('myApp', []);
   app.controller('myCtrl', function($scope) {
   var str = $scope.palcheck
   $scope.check = str === str.split('').reverse().join('');   
   ng-if="palcheck"
});
</script>


</body>
</html>
Jerad Hobgood
  • 49
  • 1
  • 1
  • 5
  • Use your Browser to debug JavaScript. Chrome and Firefox have a console with a JavaScript debugger where you can set breakpoints and make the script stop at erroneous lines. – moestly Mar 28 '17 at 20:07
  • What is your question here? What is the error? SO isn't a website to debug your code! – Sébastien Temprado Mar 28 '17 at 20:19
  • He is new to coding. He legitimately wants to know what about this code isn't working. If this isn't a place for new programmers to come and get help, then that is news to me. – frosty Mar 28 '17 at 21:08

1 Answers1

1

I would add a change listener to the input, and then set the value of it is is a match in that listener.

<!DOCTYPE html>
<html>
<script 
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js">
</script>
<body>

<div ng-app="myApp" ng-controller="myCtrl">
    Name: <input ng-model="palcheck" ng-change="onChange()">
    <h1>{{palcheck}}</h1>
    <h1>Is Match: {{isMatch}}</h1>        
</div>

<script>
    var app = angular.module('myApp', []);
    app.controller('myCtrl', function($scope) {

        $scope.onChange = function(){
            $scope.isMatch = str === str.split('').reverse().join('');   
        };

    });
</script>


</body>
</html>
frosty
  • 21,036
  • 7
  • 52
  • 74