angularjs-ng-init

Angular : ng-init does not run on load

两盒软妹~` 提交于 2020-01-01 08:20:48
问题 I have seen a few exmaples on stack overflow about this ng-init issue, although I cant seem to find one which references it with the use of a controller. I have called the function in the controller by having the following in the html file <div class="tab-container" ng-controller = "ExampleController" ng-init = "init()" > In the controller: $scope.init = function(){ alert("do something"); }; It does run, but it runs before the components have loaded on the screen. Am i missing something?

correct way to initialise scope values when the view is loaded with angularjs, ngInit?

倖福魔咒の 提交于 2019-12-30 09:38:17
问题 I've been learning angularJs for the past few weeks and been looking at a number of large scale apps to see how things work in the real world. In most of them I have noticed when a view is loaded : ng-init="init()" i.e. the function init() is called in the relevant controller. Is used to set the initial values. BUT(big but) when reading through the angular docs on ngInit i came to a rather stern looking description: "The only appropriate use of ngInit for aliasing special properties of

Does ng-init watch over change on instantiated property like ng-model does?

老子叫甜甜 提交于 2019-12-30 08:53:11
问题 Does ng-init watch over change on instantiated property like ng-model does? Apparently not, so I set a watch as shown below: app.js var app = angular.module('plunker', []); app.controller('MainCtrl', function($scope) { $scope.$watch('myProp1', function(newVal, oldVal){ $scope.myProp1 = newVal }) }); html <body ng-controller="MainCtrl"> <input ng-init='myProp="my property"'>{{myProp}}</br> <input ng-init='myProp1="my 1 property"'>{{myProp1}}</br> <input ng-init='myProp11="my 11 property"' ng

Does ng-init watch over change on instantiated property like ng-model does?

空扰寡人 提交于 2019-12-30 08:52:31
问题 Does ng-init watch over change on instantiated property like ng-model does? Apparently not, so I set a watch as shown below: app.js var app = angular.module('plunker', []); app.controller('MainCtrl', function($scope) { $scope.$watch('myProp1', function(newVal, oldVal){ $scope.myProp1 = newVal }) }); html <body ng-controller="MainCtrl"> <input ng-init='myProp="my property"'>{{myProp}}</br> <input ng-init='myProp1="my 1 property"'>{{myProp1}}</br> <input ng-init='myProp11="my 11 property"' ng

how to set default value after ng-options completed?

风格不统一 提交于 2019-12-24 07:49:54
问题 assume that this is my controller: function MainController(BaseInformation, baseInformationConstants) { var vm = this; getGenders(); function getGenders() { vm.genders = BaseInformation.list({headerId: baseInformationConstants.genderId}); } } and this select tag, that i want to set default value for it with ng-init , but it didn't worked: <select ng-init="vm.user.genderId = {id: vm.genders[0].id}" ng-model="vm.user.genderId" ng-options="gender.id as gender.topic for gender in vm.genders track

ng-init json Object

落花浮王杯 提交于 2019-12-23 20:09:33
问题 I use angularjs (ng-init) and I want to assign value to variable as jsonObj. I try this one but it doesn't work. ng-init="percentObj = [{ "value":40,"color":"#F5A623" },{ "value":60,"color":"#F5A623" }]; and another question I want to assign value like percentObj = [{ "value": parseInt($scope.projectData[0].value),"color":"#F5A623" },{ "value": parseInt($scope.projectData[0].value),"color":"#F5A623" }] How to fix this problem?? Thx 回答1: You can use window object for set your json : <script

Angular passing scope to ng-include

孤者浪人 提交于 2019-12-17 15:39:48
问题 I have a controller that I wrote that I use in multiple places in my app with ng-include and ng-repeat , like this: <div ng-repeat="item in items" ng-include="'item.html'" ng-controller="ItemController" ></div> In the controller/template, I expect the item value to exist, and the whole thing is built around this idea. Now, though, I need to use the controller in a slightly different way, without the ng-repeat , but still need to be able to pass in an item . I saw ng-init and thought it could

Angular passing scope to ng-include

邮差的信 提交于 2019-12-17 15:39:04
问题 I have a controller that I wrote that I use in multiple places in my app with ng-include and ng-repeat , like this: <div ng-repeat="item in items" ng-include="'item.html'" ng-controller="ItemController" ></div> In the controller/template, I expect the item value to exist, and the whole thing is built around this idea. Now, though, I need to use the controller in a slightly different way, without the ng-repeat , but still need to be able to pass in an item . I saw ng-init and thought it could

AngularJS - Accessing ng-init variables from run method

浪尽此生 提交于 2019-12-14 03:49:35
问题 1) I have variables initialized in ng-init Eg - ng-init="password='Mightybear'"; 2) I want to access it from the .run method. Eg - anguar.module("ngApp", []) .run(function() { //Access password here }); Below scenarios I have tried, and did not work - 1) angular.module("ngApp", []) .run(function($rootScope) { console.log($rootScope.password) //undefined!!! }); 2) angular.module("ngApp", []) .run(function($rootScope, $timeout) { $(timeout(function() { console.log($rootScope.password) /

Passing variable from jade to ng-init not working

亡梦爱人 提交于 2019-12-12 08:56:32
问题 I'm trying to pass an object from jade to ng-init in angular This: doesn't work: ng-init='tables=!{JSON.stringify(tables)}' This: expands but, ng-init='tables=#{JSON.stringify(tables)}' the output is unescaped and filled with " s ng-init="tables={"12":{"id":.... and the view isn't updated in either of the cases. This article implies that first one should work, but like I said, it doesn't even expand, ng-init='tables=!{JSON.stringify(tables)}' in source code shows up exactly the same in the