C#, .net 4.5 and angularjs

本文关键字:and angularjs net | 更新日期: 2023-09-27 18:26:52

我对angularjs很陌生。我刚开始学习。我创建了一个简单的aspx页面,但它并没有按预期工作,但若我在html页面中创建了相同的页面,它就会工作。问题是,当点击按钮计数器应该增加,但它不适用于aspx页面,但适用于html页面

有人能告诉我的原因是什么吗

<%@ 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>

C#, .net 4.5 and angularjs

使用此

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

而不是

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

如果在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>