2015-06-09 7 views
5

Ciao Ho provato numerosi articoli e risposte da diverse domande ma non ho fortuna, sto usando un progetto ionico vuoto e gira sul mio browser con ionic.serve anche non c'è nessun errori che mostrano.Angular js Le parentesi graffe non mostrano valore in html

Il {{truck}} è mostrata nella mia applicazione piuttosto che il valore "Truck Value" e anche il {{truck}} non appare in modo permanente lampeggia appena ho aggiornare il browser.

html 
<body ng-app="starter"> 
    <div ng-controller="Ctrl"> 
     <h2>hey {{truck}}</h2> 
    </div> 
</body> 

js 

var example = angular.module('starter', ['ionic', 'ngCordova']) 
... 
example.controller("Ctrl", function() { 

     var truck = "Truck Value";        

    }); 

risposta

2
example.controller("Ctrl", function($scope) { 

     $scope.truck = "Truck Value";        

    }); 
+0

Grazie Esso mostra {{camion}} permanentemente ora, ma ancora non mostra il valore @Artemkh –

+0

non importa che ho appena avuto un errore di battitura grazie funziona @Artemkh –

+0

@RenaldoGeldenhuis Siete i benvenuti – ArtemKh

2

è necessario passare $ ambito come parametro come questo

example.controller("Ctrl", function($scope) { ... } 

e assegnare i dati a portata all'interno di questa funzione come questa

$scope.truck = "Truck Value"; 
0
example.controller("Ctrl", function($scope) { 

    $scope.truck = "Truck Value";        

}); 
+0

Questo non funzionerà senza iniettare '$ scope' nel controller. –

1

Passo $ scope come parametro e quindi prova:

var example = angular.module('starter', ['ionic', 'ngCordova']) 
... 
example.controller("Ctrl", function($script) { 

     $scope.truck = "Truck Value";        

    }); 
0

Usa vm piuttosto che $ portata in versione futura di angolare verrà rimosso come da molte discussioni in modo da fare una pratica di vm, piuttosto che $ portata

(function() { 
     'use strict'; 
    var example = angular.module('starter', ['ionic', 'ngCordova']) 
     var controllerId = 'Ctrl'; 

    example.controller(controllerId,[Ctrl]); 

     function Ctrl() { 

      var vm = this; 
      vm.truck="Truck Value"; 
      } 
    })(); 

in html 


<body ng-app="starter"> 
    <div ng-controller="Ctrl"> 
     <h2>hey {{vm.truck}}</h2> 
    </div> 
</body>