1

I am very new to the angularjs. I just started learning. I created simple aspx page but it is not working as expected but if I make same in html page it works. Thing is that when click button counter should increase but it don't work in aspx page but works in html page

So can somebody tell me what be the reason

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default2.aspx.cs" Inherits="Angular.Default2" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title></title>
  <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>
</head>
<body ng-app="" ng-init="hour=13">
  <form id="form1" runat="server">
<div ng-controller="myController">
  <button ng-click="count = count + 1">Click me!</button>
  <p>{{ count }}</p>
</div>
<script>
  function myController($scope) {
    $scope.count = 0;
  }
</script>
  </form>
</body>
</html>
5
  • And what "doesn't work"? Commented Oct 17, 2014 at 17:22
  • I edit the question. Kindly check it Commented Oct 17, 2014 at 17:23
  • i have tried, it is working for me. Commented Oct 17, 2014 at 17:52
  • Are sure it is working in webform. I am using .Net 4.5 Commented Oct 17, 2014 at 17:55
  • Hold on, posted answer, i was using brackets an IDE to check JS, it was working there, but not in IIS or asp.net website. Commented Oct 17, 2014 at 17:55

2 Answers 2

1

Use this

<input type="button" ng-click="count = count + 1" value="Click me!" />

instead of

<button ng-click="count = count + 1">Click me!</button>

Sign up to request clarification or add additional context in comments.

3 Comments

<button> might be submitting the form, whereas <input type=button.. , is not doing that. You can see that earlier solution, just refresh the page- means submitting the page/form. More info - web.archive.org/web/20110721191046/http://particletree.com/…
@John , definitely you can develop SPA using ASP.Net/Server side technology, but you have to be careful while do so, like take care of runat=server , that might manipulate control id, there can be many careful steps need to be taken. But do you see, difference , between my and your suggestion. Or are you still confused? Let me know, so that i can explain it in better words.
@ArindamNayak oh I get it, I was trying to help him with future headaches and help him understand the underlying issue, not just a quick fix.
1

it would be better if you define an app name in angular

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title></title>
  <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>
</head>
<body ng-app="myapp" ng-init="hour=13">
  <form id="form1" runat="server">
<div ng-controller="myController">
  <button ng-click="click()">Click me!</button>
  <p>{{ count }}</p>
</div>
<script>
  angular.module('myapp').controller('myController', ['$scope',
      function myController($scope) {
        $scope.count = 0;
        $scope.click = function(){
           $scope.count++;
        };
      }
  ]);
</script>
  </form>
</body>
</html>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.