The custom section view cannot be called for the first time when initiating a request

The custom section view button submit cannot be called addtags api on the first request, but can be called on the second request.

<div ng-controller="DamTagsController">
    <input type="text" ng-model="newTag" placeholder="Add tag">
    <button ng-click="addTag()">Add</button>
    <ul>
        <li ng-repeat="tag in tags">{{tag.Tag}}</li>
    </ul>
</div>
angular.module("umbraco").controller("DamTagsController", function ($scope, $http, $routeParams) {
    $scope.newTag = "";
    $scope.tags = [];

    $scope.addTag = function () {
        $scope.addTag = function () {
            var data = {
                mediaId: $routeParams.id,
                tag: $scope.newTag,
                websiteIds: [1058, 1059]
            };
            $http.post("/umbraco/api/damtags/addtags", data)
                .then(function (response) {

                });
        };
    };

    $scope.loadTags = function (mediaId) {
        $http.get("/umbraco/api/damtags/gettags", { params: { mediaId: mediaId } })
            .then(function (response) {
                $scope.tags = response.data;
            });
    };
    $scope.loadTags(111);
});

headbartitle

Your $scope.addTag in your example is listed twice. Is that correct or a mistake with copying your code? You’ll need to use one $scope.addTag

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.