javascript - Angular js Curly braces doesnt show value in html - Stack Overflow

Hi I have tried numerous articles and answers from different questions but no luck, I am using a blank

Hi I have tried numerous articles and answers from different questions but no luck, I am using a blank ionic project and it runs on my browser with ionic.serve also there isn't any errors showing.

The {{truck}} is shown in my application rather than the value "Truck Value" and also the {{truck}} does not permanently appear it blinks as soon as I refresh the 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";                               

    });

Hi I have tried numerous articles and answers from different questions but no luck, I am using a blank ionic project and it runs on my browser with ionic.serve also there isn't any errors showing.

The {{truck}} is shown in my application rather than the value "Truck Value" and also the {{truck}} does not permanently appear it blinks as soon as I refresh the 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";                               

    });
Share asked Jun 9, 2015 at 9:13 user2413453user2413453
Add a ment  | 

5 Answers 5

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

      $scope.truck = "Truck Value";                               

    });

you need to pass $scope as a parameter like this

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

and assign your data to scope inside this function like this

$scope.truck = "Truck Value";

Pass $scope as a parameter and then try:

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

      $scope.truck = "Truck Value";                               

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

  $scope.truck = "Truck Value";                               

});

Use vm rather than $scope in future release of angular it will be removed as per many discussion so make a practice of vm rather than $scope

    (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>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744820550a4595589.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信