Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/429.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 角度-@角度/普通,无NPM_Javascript_Angular - Fatal编程技术网

Javascript 角度-@角度/普通,无NPM

Javascript 角度-@角度/普通,无NPM,javascript,angular,Javascript,Angular,我试图在代码中使用ng template指令,以便能够在按钮单击事件后显示div,但我无法使其工作,因为我需要有angular/common库。我试图通过添加脚本标记来引用它 <script src="https://cdn.jsdelivr.net/npm/@angular/common@11.0.2/bundles/common.umd.min.js" integrity="sha256-+HBVhNZwWCgkN0Z0tvWyjqjm+yI9F/szNt

我试图在代码中使用ng template指令,以便能够在按钮单击事件后显示div,但我无法使其工作,因为我需要有angular/common库。我试图通过添加脚本标记来引用它

<script src="https://cdn.jsdelivr.net/npm/@angular/common@11.0.2/bundles/common.umd.min.js" integrity="sha256-+HBVhNZwWCgkN0Z0tvWyjqjm+yI9F/szNt3Yz4/0/ws=" crossorigin="anonymous"></script>
我被卡住了,不知道如何才能使用ng模板指令

HTML(index.HTML):


是否可以通过脚本标记引用@angular/common模块,还是需要通过NPM引用它?

我认为这里的问题是所使用的版本

您提供的代码是在
Angular.js
代码中编写的,
@Angular/common
是一个
Angular
模块

要使代码正常工作,您需要这样做

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.0/angular.min.js"></script>

,顺便说一句,这是不推荐的


在Angular和Angular.js之间,我添加了脚本标记,但我仍然无法使ng模板和*ngIf(toggle div show/hide)工作。@Joseph*ngIf和都是
Angular
语法,而不是
Angular.js
。在这里,您可以找到使用ngIf(ng-if)旧语法的文档。Angular.js中没有作为ng模板的指令
<ng-template>
    <div class="container">
        <h2>Edit or Delete an Evangelist</h2>
        <form name="userEditForm">
            <p>person id:     <input type="text" id="name" ng-model="userEdit.personid" disabled /></p>
            <p>name:     <input type="text" id="name" ng-model="userEdit.name" /></p>
            <p>location: <input type="text" id="location" ng-model="userEdit.location" /></p>
            <button id="btn-edit-evangelist" class="btn btn-primary" ng-click="editName(userEdit)">Save</button>
            <button id="btn-canceledit-evangelist" class="btn btn-default btn" ng-click="delName(userEdit);">Delete User</button>
        </form>
    </div>
    <div *ngIf="isEdit">
    </div>
</ng-template>
"use strict";

angular.module('MainApp', [
])


.controller("MainController", function ($scope, $http) {

    //initialize scope variables
    $scope.user = {
        name: function (theName) {
            if (angular.isDefined(theName)) {
                $scope._name = theName;
            }
            return $scope._name;
        }(),
        location: function (theLocation) {
            if (angular.isDefined(theLocation)) {
                $scope._location = theLocation;
            }
            return $scope._location;
        }()
    };


    function redirectToEdit(user) {
        this.isEdit = !this.isEdit;

        var id = user.personid;

        $http.get('https://webapimongodb.herokuapp.com/api/name/' + id, {
            params: { personid: user.personid, name: user.name, location: user.location },
            headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
        })
            .success(function (res) {
                console.log(res);
                $scope.userEdit.personid = res.personid;
                $scope.userEdit.name = res.Name;
                $scope.userEdit.location = res.Location;
            });

    }


})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.0/angular.min.js"></script>