Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/425.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 有角度的js花括号在html中不显示值_Javascript_Html_Angularjs_Ionic Framework_Ionic - Fatal编程技术网

Javascript 有角度的js花括号在html中不显示值

Javascript 有角度的js花括号在html中不显示值,javascript,html,angularjs,ionic-framework,ionic,Javascript,Html,Angularjs,Ionic Framework,Ionic,您好,我尝试了许多文章和不同问题的答案,但运气不好,我使用的是一个空白的ionic项目,它在我的浏览器上与ionic.serve一起运行,也没有显示任何错误 (function () { 'use strict'; var example = angular.module('starter', ['ionic', 'ngCordova']) var controllerId = 'Ctrl'; example.controller(con

您好,我尝试了许多文章和不同问题的答案,但运气不好,我使用的是一个空白的ionic项目,它在我的浏览器上与ionic.serve一起运行,也没有显示任何错误

    (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>
我的应用程序中显示的是
{{truck}
,而不是
值“truck value”
而且,
{{truck}}
不会永久出现,只要我刷新浏览器,它就会闪烁

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";                               

    });
    (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>
html
嘿{{卡车}
js
变量示例=angular.module('starter',['ionic','ngCordova']))
...
示例.控制器(“Ctrl”,函数(){
var truck=“卡车价值”;
});

您需要将$scope作为如下参数传递

example.controller("Ctrl", function($scope) { ... }
$scope.truck = "Truck Value";
    (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>
并将您的数据分配到此函数中的作用域,如下所示

example.controller("Ctrl", function($scope) { ... }
$scope.truck = "Truck Value";
    (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>

将$scope作为参数传递,然后重试:

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

      $scope.truck = "Truck Value";                               

    });
    (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>

在angular的未来版本中使用vm而不是$scope。根据许多讨论,它将被删除,因此请使用vm而不是$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>
(函数(){
"严格使用",;
变量示例=angular.module('starter',['ionic','ngCordova']))
var controllerId='Ctrl';
示例.控制器(controllerId[Ctrl]);
函数Ctrl(){
var vm=这个;
vm.truck=“卡车价值”;
}
})();
在html中
嘿{{vm.truck}

如果不将
$scope
注入控制器,这将无法工作。谢谢,它现在永久显示{{truck},但仍然不显示@Artemkh的值