i wish to use angular in rails mounted engine. now what i added:
in master applications:
ng-app
to the main html tag
angular.js
file in assets/javascript
in the rails mounted engine:
div ng-controller="Ctrl"
with {{ title }}
var app = angular.module('app', []).controller('Ctrl', function($scope) { $scope.title = "42"; });
now what i got is:
instead of 42
i see {{title}}
when i console.log(angular)
i see its defined
if instead of ng-app
in master application i use angular.bootstrap
it doesn't work
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.