AngularJS ng-click属性未在ng-repeat中对发布请求进行更新

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

这是目录的哈巴狗文件

doctype html
html
    head
        title Tradecademy
        meta(name="viewport", content="width=device-width, initial-scale=1")
        script(src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js")
        script(src="https://code.angularjs.org/1.5.6/angular-sanitize.min.js")
        link(rel="stylesheet", href="https://www.w3schools.com/w3css/4/w3.css")
        link(rel="stylesheet", href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css")
        link(rel="stylesheet", href="https://fonts.googleapis.com/css?family=Montserrat")
        link(href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css", rel="stylesheet", integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh", crossorigin="anonymous")
        script(src="./includes/catalog.js")
    body(ng-app="catalog" ng-controller="catalogController")
        include ./includes/appheader.pug
        .w3-display-container
            ul.w3-ul
                li
                    h2 Beginner Modules
                li
                    div(ng-repeat=("module in beginnerModules"))
                       | {{module.name}}
                       button.w3-button.w3-blue.w3-hover-teal(ng-click="buyCourse(\"{{module.name}}\")")
                li
                    h2 Advanced Modules



这是catalog.js文件

var app = angular.module('catalog', ['ngSanitize']);

app.controller("catalogController", ($scope, $http) => {
  $http({
    method : 'GET',
    url : '/catalogModules'

  }).then((response)=> {
    if(response.data.undefined == "undefined") {
      window.location.href="/"
    }
    else 
    {
      $scope.headerArray = []

      angular.forEach(response, (value) => {
        $scope.headerArray.push(value);
      });

      $scope.modules = $scope.headerArray[0];
      $scope.beginnerModules = []
      $scope.advancedModules =[]
      angular.forEach($scope.modules, (value) => {

        if(value.type == "Beginner") 
        {
          $scope.beginnerModules.push(value);
        }
        if(value.type == "Advanced") 
        {
          $scope.advancedModules.push(value);
        }
      });
    }
  $scope.buyCourse = (module) => {
        console.log(module);
        $http.post("/buyNewModule", module)
        .success(function (data, status, headers) {
          console.log($scope.beginnerCourseKey);
          console.log(data);
          console.log(status);
          console.log(headers);
        })
        .error(function (data, status, header) {
          console.log($scope.beginnerCourseKey);
          console.log(data);
          console.log(header);
          console.log(status);
        });
      }
  });
});

问题是,当它应该记录模块的名称属性时,它会记录“ {{module.name}}”。我需要能够访问实际的名称值而不是AngularJS插值。我对AngularJS还是很陌生,所以如果我做错了什么,请告诉我。 GET函数可以正常工作。

angularjs ajax post get pug
1个回答
0
投票

这是新的哈巴狗文件。

.w3-display-container
            ul.w3-ul
                li
                    h2 Beginner Modules
                li
                    div(ng-repeat=("module in beginnerModules"))
                       button.w3-button.w3-blue.w3-hover-teal(ng-click="buyCourse(module.name)")
                li
                    h2 Advanced Modules

我不确定为什么我尝试这样做时会这样做-var moduleName = module.name,它给我的错误是模块未定义。关于为什么可行的任何见解都会很好。


0
投票

这是新的哈巴狗文件。

.w3-display-container
            ul.w3-ul
                li
                    h2 Beginner Modules
                li
                    div(ng-repeat=("module in beginnerModules"))
                       button.w3-button.w3-blue.w3-hover-teal(ng-click="buyCourse(module.name)")
                li
                    h2 Advanced Modules

我不确定为什么我尝试这样做时会这样做-var moduleName = module.name,它给我的错误是模块未定义。关于为什么可行的任何见解都会很好。

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