angularjs-ng-init

Inject variables via ng-init to controller

喜你入骨 提交于 2019-12-12 07:22:25
问题 I want to inject the same variables with different values multiples times to the same controller. This is what I tried. What is a way to get different values in each call? HTML <body ng-app="myApp"> <div ng-controller="myCtrl" ng-init="test='helloworld';test1='helloworld2'"> </div> <div ng-controller="myCtrl" ng-init="test='helloworld3';test1='helloworld4'"> </div> <div ng-controller="myCtrl" ng-init="test='helloworld5';test1='helloworld6'"> </div> <body> JavaScript code var app = angular

How to $setdirty to a single input

巧了我就是萌 提交于 2019-12-10 14:42:37
问题 I've got a little problem. I want to set to dirty a single input, I mean, because when I give a value automatically it stays in pristine class, doesn't change, and doesn't save the new value. If I edit it, it works and change the class. I want to cancel that pristine class. If anyone know please let me know. <form class="form-horizontal" ng-repeat="studiant in studiants" name="form" id="form"> <input type="hidden" name="id" value="{{studiant.studiant_id}}" class="form-control" disabled> <div

setting Angular select ng-init to first value in array

天大地大妈咪最大 提交于 2019-12-09 14:51:12
问题 I have a simple select element that I am trying to enforce a value being present to submit the form and I have tried both setting the required attribute as well as using ng-init to ensure there is a value selected and both fail. I am using ng-options to create a list of values from an array of Objects that have a ref property. Then I would like to use ng-init to set the shown value to the first Object.ref in the array. <select name="refmarker" class="input-block-level form-width-adjust" ng

Ng-init via function

早过忘川 提交于 2019-12-08 23:22:46
问题 As you know, it is possible to initialize objects as follows: <div ng-init="friends = [{name:'John', phone:'555-1276'}, {name:'Mary', phone:'800-BIG-MARY'}, {name:'Mike', phone:'555-4321'}, {name:'Adam', phone:'555-5678'}, {name:'Julie', phone:'555-8765'}, {name:'Juliette', phone:'555-5678'}]"></div> Is it possible to define object similar like this but via a function: <div ng-init="init()"> My aim is actually taking the objects from an API and show them in a list via ng-repeat 回答1: The

AngularJS ngInit with Date

五迷三道 提交于 2019-12-08 15:09:31
问题 I'm coding in .NET MVC and would like to pass a stored DateTime object to the front-end as an initial value for a Date object in a controller. Here's what I've tried: ng-init="params.datetime = new Date()" This doesn't seem to work, and I'm getting a syntax error. How can I pass in a Date object as an initial property for a scope variable? http://jsfiddle.net/xX8LJ/ UPDATE I forgot to include the Razor code in my code sample. ng-init="params.datetime = new Date('@Model.DepartureTime.ToString(

Passing variable from jade to ng-init not working

寵の児 提交于 2019-12-04 14:58:27
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 HTML source ng-init='tables=!{JSON.stringify(tables)}' Actually, the #{...} approach seems to work fine.

setting Angular select ng-init to first value in array

≯℡__Kan透↙ 提交于 2019-12-04 00:27:01
I have a simple select element that I am trying to enforce a value being present to submit the form and I have tried both setting the required attribute as well as using ng-init to ensure there is a value selected and both fail. I am using ng-options to create a list of values from an array of Objects that have a ref property. Then I would like to use ng-init to set the shown value to the first Object.ref in the array. <select name="refmarker" class="input-block-level form-width-adjust" ng-model="model.refmarker" ng-options="rm.ref for rm in refmarkers" ng-disabled="editable" ng-init="model

Inject variables via ng-init to controller

ε祈祈猫儿з 提交于 2019-12-01 00:29:37
I want to inject the same variables with different values multiples times to the same controller. This is what I tried. What is a way to get different values in each call? HTML <body ng-app="myApp"> <div ng-controller="myCtrl" ng-init="test='helloworld';test1='helloworld2'"> </div> <div ng-controller="myCtrl" ng-init="test='helloworld3';test1='helloworld4'"> </div> <div ng-controller="myCtrl" ng-init="test='helloworld5';test1='helloworld6'"> </div> <body> JavaScript code var app = angular.module("myApp", []); app.controller("myCtrl", ["$scope",function($scope) { console.log($scope.test);

Pass parameter to Angular ng-include

混江龙づ霸主 提交于 2019-11-30 04:11:37
I am trying to display a binary tree of elements, which I go through recursively with ng-include. What is the difference between ng-init="item = item.left" and ng-repeat="item in item.left" ? In this example it behaves exactly the same, but I use similiar code in a project and there it behaves differently. I suppose it's because of Angular scopes. Maybe I shouldn't use ng-if, please explain me how to do it better. The pane.html is: <div ng-if="!isArray(item.left)"> <div ng-repeat="item in [item.left]" ng-include="'Views/pane.html'"> </div> </div> <div ng-if="isArray(item.left)"> {{item.left[0]

Pass parameter to Angular ng-include

被刻印的时光 ゝ 提交于 2019-11-29 02:03:46
问题 I am trying to display a binary tree of elements, which I go through recursively with ng-include. What is the difference between ng-init="item = item.left" and ng-repeat="item in item.left" ? In this example it behaves exactly the same, but I use similiar code in a project and there it behaves differently. I suppose it's because of Angular scopes. Maybe I shouldn't use ng-if, please explain me how to do it better. The pane.html is: <div ng-if="!isArray(item.left)"> <div ng-repeat="item in