Вопрос

I have this code:

<li ng-repeat="objekt in driversList" class="mix {{objekt.Objekt.Type}}">
  <a href="objekttest.html"  data-ajax="false"
     ng-click="objekt.Objekt.Active='yes'">
    <img ng-src="../images/thumbs/{{objekt.Objekt.Thumb}}.jpg"
         style="margin-right:0;" >
    <span id="list">{{objekt.Objekt.Name}}{{objekt.Objekt.Active}}</span>
    <span id="listmala">{{objekt.Objekt.Type}}</span>
  </a>
</li>

objekt.Objekt.Active changes when I click the corresponding <li> tag.

However, on the other HTML link, I have:

<div ng-repeat="objekt in driversList">
  {{objekt.Objekt.Name}} {{objekt.Objekt.Active}}
</div>

This time, objekt.Objekt.Active keeps the default value (i.e. 'no').

Is it possible to change a scope variable permanently so that it is changed on some other HTML element?

Here's my controller code:

angular.module('aki', [
        'aki.controllers'
    ]);

    angular.module('aki.controllers', []).
    controller('akicontroller', function($scope,$rootScope) {
    //$scope.toggle = function(){
        //$scope.driversList.
    //}
    $rootScope.active='da';
    $scope.driversList = [
      {
          Objekt: {
              Name: 'Saint & Sinner',
              Type: 'nightclub',
              Thumb: 'Sinner',
              Active:'no'         
          }
      },
      {
          Objekt: {
              Name: 'Corner Cafe',
              Type: 'cafe',
              Thumb: 'corner caffe',
              Active:'no'
          }
      },...
...

EDIT: I'm making multipage application without Ajax

Это было полезно?

Решение

Not without using some form of backend or storage.

Looking at your code, you appear to have hard coded the driversList into the .js file. You're also navigating to a new page, it appears. AngularJS doesn't edit that JS file, so that's not going to persist.

You'll need to either have a backend service that stores the state (in memory or database) via http request, have AngularJS not actually change location (putting all of this on the same page, and show/hiding it as you interact), or use something like HTMLStorage to save/load the data.

You can also use something like AngularJS's Firebase backend to serve as persistence for the data - https://www.firebase.com/quickstart/angularjs.html has a quick start guide.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top