我的Angular应用程序脚本不执行

问题描述 投票:0回答:2

下面的页面基于Visual Studio为新的Angular Web应用程序生成的示例Angular页面:

<h1>Member Module</h1>

<p>This is a simple example of an Angular component.</p>

<p aria-live="polite">Current count: <strong>{{ currentCount }}</strong></p>

<button class="btn btn-primary" (click)="incrementCounter()">Increment</button>

<div ng-app="myApp" ng-controller="myController">
  <table>
    <tr ng-repeat="x in portfolios">
      <td>{{ x }}</td>
    </tr>
  </table>
</div>

<script>
  var app = angular.module('myApp', []);
  app.controller('myController', function ($scope, $http) {
    $http.get("https://localhost:44319/api/Portfolio")
      .then(function (response) { $scope.portfolios = response.text(); });
  });
</script>

按钮计数器起作用,因此几乎可以确认是否存在Angular支持。

我已在该页面中添加了一些其他角度代码。从div标签开始是一些示例代码,这些代码基于我在此处找到的教程:https://www.w3schools.com/angular/angular_sql.asp。这将是我首次尝试从后端SQL Server提取数据并使用Angular将其显示在网页上。

我已经在控制器内部设置了一个断点:https://localhost:44319/api/Portfolio

如果我在浏览器窗口中手动命中该URL,则会按预期命中断点。但是,当我加载页面时,没有断点。因此该脚本未在运行,但我不明白为什么不这样做。

您能帮我吗?谢谢!

c# angularjs
2个回答
0
投票

将您的api调用移至某个函数,然后像调用该函数一样


0
投票

谢谢大家阐明这一点。我的示例失败,因为我一直在将Angular与AngularJS合并。我的由Visual Studio 2019制作的项目是Angular NOT AngularJS。但是我从网络上提取的示例是AngularJS-当然,它是行不通的。

© www.soinside.com 2019 - 2024. All rights reserved.