简体   繁体   中英

Angular in rails mounted engine

i wish to use angular in rails mounted engine. now what i added:

in master applications:

  1. ng-app to the main html tag

  2. angular.js file in assets/javascript

in the rails mounted engine:

  1. div ng-controller="Ctrl" with {{ title }}

  2.  var app = angular.module('app', []).controller('Ctrl', function($scope) { $scope.title = "42"; }); 

now what i got is:

  1. instead of 42 i see {{title}}

  2. when i console.log(angular) i see its defined

  3. if instead of ng-app in master application i use angular.bootstrap it doesn't work

  4. if i do angular.bootstrap after 5 seconds, it works (tried document.ready, doesn't help)

now most how'tos i saw either were not complete or required a lot of dependencies and refactoring and i hope it can be done faster.

Use $scope :

'use strict';

angular.module('app', []).controller('Ctrl', ['$scope', function($scope) {
  $scope.title = "42";
}]);

Or you can inject '$rootScope'

in template:

 <body ng-app="app">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM