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
5 Answers
Reset to default 2example.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条)